pub struct StackAddr { /* private fields */ }Expand description
A stack address that contains a stack of protocols. The stack address can be used to represent a network address with multiple protocols.
Implementations§
Source§impl StackAddr
impl StackAddr
Sourcepub fn from_parts(segments: &[Segment]) -> Self
pub fn from_parts(segments: &[Segment]) -> Self
Create a new StackAddr from a slice of segments.
Sourcepub fn with(self, segment: Segment) -> Self
pub fn with(self, segment: Segment) -> Self
Create a new StackAddr with a single segment.
This is a convenience method for creating a stack address with builder pattern.
Sourcepub fn with_protocol(self, protocol: Protocol) -> Self
pub fn with_protocol(self, protocol: Protocol) -> Self
Create a new StackAddr with a single protocol segment.
This is a convenience method for creating a stack address with builder pattern.
Sourcepub fn with_identity(self, identity: Identity) -> Self
pub fn with_identity(self, identity: Identity) -> Self
Create a new StackAddr with a single identity segment.
This is a convenience method for creating a stack address with builder pattern.
Sourcepub fn with_path(self, path: &str) -> Self
pub fn with_path(self, path: &str) -> Self
Create a new StackAddr with a single path segment.
This is a convenience method for creating a stack address with builder pattern.
Sourcepub fn with_meta(self, key: &str, value: &str) -> Self
pub fn with_meta(self, key: &str, value: &str) -> Self
Create a new StackAddr with a single metadata segment.
This is a convenience method for creating a stack address with builder pattern.
Sourcepub fn with_mac(self, addr: MacAddr) -> Self
pub fn with_mac(self, addr: MacAddr) -> Self
Create a new StackAddr with a MAC address segment.
This is a convenience method for creating a stack address with builder pattern.
Sourcepub fn try_with_mac_str(self, addr: &str) -> Result<Self, StackAddrError>
pub fn try_with_mac_str(self, addr: &str) -> Result<Self, StackAddrError>
Create a new StackAddr with a MAC address segment from a string.
Sourcepub fn with_ipv4(self, addr: Ipv4Addr) -> Self
pub fn with_ipv4(self, addr: Ipv4Addr) -> Self
Create a new StackAddr with an IPv4 address segment.
This is a convenience method for creating a stack address with builder pattern.
Sourcepub fn with_ipv6(self, addr: Ipv6Addr) -> Self
pub fn with_ipv6(self, addr: Ipv6Addr) -> Self
Create a new StackAddr with an IPv6 address segment.
This is a convenience method for creating a stack address with builder pattern.
Sourcepub fn with_ip(self, addr: IpAddr) -> Self
pub fn with_ip(self, addr: IpAddr) -> Self
Create a new StackAddr with an IP address segment.
This is a convenience method for creating a stack address with builder pattern.
Sourcepub fn with_dns_name(self, name: &str) -> Self
pub fn with_dns_name(self, name: &str) -> Self
Create a new StackAddr with a DNS name segment.
This is a convenience method for creating a stack address with builder pattern.
Sourcepub fn with_dns4_name(self, name: &str) -> Self
pub fn with_dns4_name(self, name: &str) -> Self
Create a new StackAddr with a DNS4 name segment.
This is a convenience method for creating a stack address with builder pattern.
Sourcepub fn with_dns6_name(self, name: &str) -> Self
pub fn with_dns6_name(self, name: &str) -> Self
Create a new StackAddr with a DNS6 name segment.
This is a convenience method for creating a stack address with builder pattern.
Sourcepub fn segments(&self) -> &[Segment]
pub fn segments(&self) -> &[Segment]
Returns a reference to the ordered list of segments that make up this stack address.
Sourcepub fn contains(&self, target: &Segment) -> bool
pub fn contains(&self, target: &Segment) -> bool
Check if the stack address contains a specific segment.
Sourcepub fn replace(&mut self, old: &Segment, new: Segment) -> bool
pub fn replace(&mut self, old: &Segment, new: Segment) -> bool
Replace the first occurrence of a segment with a new segment.
Sourcepub fn replace_all(&mut self, old: &Segment, new: Segment) -> usize
pub fn replace_all(&mut self, old: &Segment, new: Segment) -> usize
Replace all occurrences of a segment with a new segment.
Sourcepub fn remove(&mut self, target: &Segment) -> bool
pub fn remove(&mut self, target: &Segment) -> bool
Remove the first occurrence of a segment from the stack address.
Sourcepub fn remove_all(&mut self, target: &Segment) -> usize
pub fn remove_all(&mut self, target: &Segment) -> usize
Remove all occurrences of a segment from the stack address.
Sourcepub fn protocols(&self) -> Vec<&Protocol>
pub fn protocols(&self) -> Vec<&Protocol>
Returns all Protocol segments in the stack address.
This filters out non-protocol segments such as identities, paths, and metadata.
Sourcepub fn transport(&self) -> Option<TransportProtocol>
pub fn transport(&self) -> Option<TransportProtocol>
Extract the transport protocol (if any) from the address.
pub fn ip(&self) -> Option<IpAddr>
Sourcepub fn socket_addr(&self) -> Option<SocketAddr>
pub fn socket_addr(&self) -> Option<SocketAddr>
Get the socket address from the stack address.
Sourcepub fn host_port(&self) -> Result<(String, u16), StackAddrError>
pub fn host_port(&self) -> Result<(String, u16), StackAddrError>
Get the host (IP or DNS) and port pair, returning an error when either is missing.
Sourcepub fn socket_addrs(&self) -> Result<Vec<SocketAddr>, StackAddrError>
pub fn socket_addrs(&self) -> Result<Vec<SocketAddr>, StackAddrError>
Resolve the address into concrete SocketAddr values using the system resolver.
This helper makes it easy to hand a StackAddr directly to networking libraries
that expect socket addresses or types implementing ToSocketAddrs. It will
return an error when host or port information is missing, or if DNS resolution
fails.
Sourcepub fn resolved(&self) -> bool
pub fn resolved(&self) -> bool
Check if the stack address is resolved. A stack address is considered resolved if it contains an IP address.
Sourcepub fn get_ip(&self) -> Option<&Protocol>
pub fn get_ip(&self) -> Option<&Protocol>
Returns the first IP protocol segment (Ip4 or Ip6) if present.
Sourcepub fn get_dns(&self) -> Option<&Protocol>
pub fn get_dns(&self) -> Option<&Protocol>
Returns the first DNS protocol segment (Dns, Dns4, or Dns6) if present.
Sourcepub fn get_identity(&self) -> Option<&Identity>
pub fn get_identity(&self) -> Option<&Identity>
Returns the first identity segment (NodeId, PeerId, UUID, or Custom) if present.
Trait Implementations§
Source§impl Ord for StackAddr
impl Ord for StackAddr
Source§impl PartialOrd for StackAddr
impl PartialOrd for StackAddr
Source§impl ToSocketAddrs for StackAddr
impl ToSocketAddrs for StackAddr
Source§type Iter = IntoIter<SocketAddr>
type Iter = IntoIter<SocketAddr>
Source§fn to_socket_addrs(&self) -> Result<Self::Iter>
fn to_socket_addrs(&self) -> Result<Self::Iter>
SocketAddrs. Read more