| Crates.io | stackaddr |
| lib.rs | stackaddr |
| version | 0.7.0 |
| created_at | 2025-03-22 16:37:16.272305+00 |
| updated_at | 2025-09-25 15:10:28.016359+00 |
| description | Self-describing, layered network address representation, with flexible protocol stacks. |
| homepage | |
| repository | https://github.com/foctal/stackaddr |
| max_upload_size | |
| id | 1601946 |
| size | 63,583 |
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.
Segment]s
/ip4, /tcp, /tls, /http/node/<base32>, /uuid/<uuid>/meta/env/production/foo/bar/ip4/127.0.0.1/udp/4433/quic/mac/aa:bb:cc:dd:ee:ff/ip4/192.168.1.1/tcp/80/httpfeatures = ["serde"]FromStr, Display, and error types for easy parsingAdd stackaddr to your dependencies:
[dependencies]
stackaddr = "0.7"
To enable serde support:
[dependencies]
stackaddr = { version = "0.7", features = ["serde"] }
Basic:
use stackaddr::{StackAddr, Protocol, Segment};
let addr = StackAddr::from_parts(&[
Segment::Protocol(Protocol::Ip4("192.168.1.1".parse().unwrap())),
Segment::Protocol(Protocol::Tcp(443)),
Segment::Protocol(Protocol::Tls),
Segment::Protocol(Protocol::Http),
]);
println!("{}", addr);
// 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("parse failed");
With identity:
let public_key: [u8; 32] = generate_public_key();
let id = Bytes::copy_from_slice(&public_key);
let addr = StackAddr::from_parts(&[
Segment::Protocol(Protocol::Ip4("192.168.10.10".parse().unwrap())),
Segment::Protocol(Protocol::Udp(4433)),
Segment::Protocol(Protocol::Quic),
Segment::Identity(Identity::NodeId(id)),
]);
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();
Inspired by Multiaddr, StackAddr inherits its core ideas while embracing Rust’s flexibility to provide a more general-purpose and extensible address representation.