| Crates.io | ipv6-ddn |
| lib.rs | ipv6-ddn |
| version | 0.1.0 |
| created_at | 2025-11-22 05:13:01.261409+00 |
| updated_at | 2025-11-22 05:13:01.261409+00 |
| description | A library to convert between Standard IPv6 (Hex) and IPv6 Decimal Dot Notation (DDN). |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1944822 |
| size | 38,101 |
A lightweight, zero-dependency Rust library to convert IPv6 addresses between the standard Hexadecimal format and the experimental Decimal Dot Notation (IPv6-DDN).
IPv6 Decimal Dot Notation (IPv6-DDN) is a proposed format designed to make IPv6 addresses more readable for humans familiar with IPv4.
Instead of using hexadecimal blocks separated by colons (e.g., 2001:db8::1), IPv6-DDN represents the 128-bit address as 8 segments of 16-bit decimal integers (0-65535) separated by dots (.).
| Format | Example |
|---|---|
| Standard IPv6 | 2001:db8::1 |
| IPv6-DDN | 8193.3512..1 |
It supports zero-compression using double dots (..) similar to the double colon (::) in standard IPv6.
std::net).Add this to your Cargo.toml.
[dependencies]
ipv6_ddn = "0.1.0"
use ipv6_ddn::{from_standard_str, to_standard_str, get_type, AddressType};
fn main() {
// 1. Convert Standard IPv6 to DDN
let ddn = from_standard_str("2001:db8::1").unwrap();
println!("DDN: {}", ddn); // Output: "8193.3512..1"
// 2. Convert DDN to Standard IPv6
let std = to_standard_str("8193.3512..1").unwrap();
println!("Standard: {}", std); // Output: "2001:db8::1"
// 3. Detect Type
let ip_type = get_type("8193.3512..1");
match ip_type {
AddressType::IPv6DDN => println!("Detected IPv6-DDN address!"),
AddressType::IPv6 => println!("Detected Standard IPv6 address!"),
AddressType::IPv4 => println!("Detected IPv4 address!"),
AddressType::Unknown => println!("Unknown format"),
}
}
from_standard_str(standard_ip: &str) -> Result<String, String>Converts a Standard IPv6 string (Hex:Colon) to Decimal Dot Notation.
2001:db8::1).Ok(String) containing the canonical IPv6-DDN string.Err if the input format is invalid.to_standard_str(ddn_ip: &str) -> Result<String, String>Converts an IPv6-DDN string (Decimal.Dot) to Standard IPv6 notation.
8193.3512..1).Ok(String) containing the canonical Standard IPv6 string.Err if the input format is invalid, contains invalid characters, or segments exceed 65535.get_type(ipaddr_text: &str) -> AddressTypeDetects the format of a given IP address string.
AddressType enum variant:
AddressType::IPv4AddressType::IPv6AddressType::IPv6DDNAddressType::Unknownis_ddn(ipaddr_text: &str) -> boolChecks if a string is a valid IPv6-DDN address.
true if valid, false otherwise.| Function | Input | Output |
|---|---|---|
from_standard_str |
::1 |
..1 |
from_standard_str |
2001:db8:0:0:1:0:0:1 |
8193.3512.0.0.1..1 |
to_standard_str |
.. |
:: |
to_standard_str |
0010..1 |
a::1 |
get_type |
192.168.1.1 |
AddressType::IPv4 |
This library includes a comprehensive unit test suite covering edge cases, compression rules, and error handling.
cargo test
This project is licensed under the Mozilla Public License 2.0 (MPL 2.0) and additional terms.
For more details, see the LICENSE and LICENSE.additional files.