stackaddr

Self-describing, layered address representation library, designed with flexibility and extensibility.
stackaddr provides a type-safe, composable, and future-proof way to represent complex address stacks, including transport protocols, cryptographic identities, metadata, and resource paths.
Features
- Segment-based architecture: each address consists of typed [
Segment]s- Protocols like
/ip4,/tcp,/tls,/http - Identities like
/node/<base32>,/uuid/<uuid> - Metadata like
/meta/env/production - Path-like entries like
/foo/bar
- Protocols like
- Layered from L2 to L7: supports MAC, IP, TCP/UDP, TLS, HTTP, and more
/ip4/127.0.0.1/udp/4433/quic/mac/aa:bb:cc:dd:ee:ff/ip4/192.168.1.1/tcp/80/http
- serde support(optional): enable with
features = ["serde"] - Easy parsing: implements
FromStr,Display, and error types for easy parsing
Usage
Add stackaddr to your dependencies:
[]
= "0.8"
To enable serde support:
[dependencies]
stackaddr = { version = "0.8", features = ["serde"] }
Example
Basic:
use ;
let addr = from_parts;
println!;
// Output: /ip4/192.168.1.1/tcp/443/tls/http
From L2 to L4:
let s = "/mac/aa:bb:cc:dd:ee:ff/ip4/192.168.1.1/tcp/8080";
let addr: StackAddr = s.parse.expect;
With identity:
let public_key: = generate_public_key;
let id = copy_from_slice;
let addr = from_parts;
With path:
let addr: StackAddr = "/dns/example.com/tcp/443/tls/http/images/logo.png".parse.unwrap;
With metadata:
let addr: StackAddr = "/meta/env/production".parse.unwrap;
Resolving to socket addresses:
use ToSocketAddrs;
let addr: StackAddr = "/dns/localhost/tcp/443".parse.unwrap;
// Structured host/port extraction
let = addr.host_port.unwrap;
assert_eq!;
// System resolution for libraries expecting concrete socket addresses
let addrs = addr.socket_addrs.unwrap;
assert!;
// Or hand it directly to APIs that accept `ToSocketAddrs`
for sock in addr.to_socket_addrs.unwrap
Acknowledgment
Inspired by Multiaddr, StackAddr inherits its core ideas and provide a more general-purpose and extensible address representation.