StackAddr

Struct StackAddr 

Source
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

Source

pub fn new(segments: Vec<Segment>) -> Self

Create a new StackAddr with the given segments.

Source

pub fn from_parts(segments: &[Segment]) -> Self

Create a new StackAddr from a slice of segments.

Source

pub fn empty() -> Self

Create a new StackAddr with no segments.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn try_with_mac_str(self, addr: &str) -> Result<Self, StackAddrError>

Create a new StackAddr with a MAC address segment from a string.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn segments(&self) -> &[Segment]

Returns a reference to the ordered list of segments that make up this stack address.

Source

pub fn push(&mut self, segment: Segment)

Push a new segment to the stack address.

Source

pub fn pop(&mut self) -> Option<Segment>

Pop the last segment from the stack address.

Source

pub fn contains(&self, target: &Segment) -> bool

Check if the stack address contains a specific segment.

Source

pub fn replace(&mut self, old: &Segment, new: Segment) -> bool

Replace the first occurrence of a segment with a new segment.

Source

pub fn replace_all(&mut self, old: &Segment, new: Segment) -> usize

Replace all occurrences of a segment with a new segment.

Source

pub fn remove(&mut self, target: &Segment) -> bool

Remove the first occurrence of a segment from the stack address.

Source

pub fn remove_all(&mut self, target: &Segment) -> usize

Remove all occurrences of a segment from the stack address.

Source

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.

Source

pub fn transport(&self) -> Option<TransportProtocol>

Extract the transport protocol (if any) from the address.

Source

pub fn mac(&self) -> Option<MacAddr>

Get the MAC address from the stack address.

Source

pub fn ip(&self) -> Option<IpAddr>

Source

pub fn port(&self) -> Option<u16>

Get the port number from the stack address.

Source

pub fn socket_addr(&self) -> Option<SocketAddr>

Get the socket address from the stack address.

Source

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.

Source

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.

Source

pub fn name(&self) -> Option<&str>

Get the DNS name from the stack address.

Source

pub fn resolved(&self) -> bool

Check if the stack address is resolved. A stack address is considered resolved if it contains an IP address.

Source

pub fn is_empty(&self) -> bool

Check if the stack address is empty.

Source

pub fn get_ip(&self) -> Option<&Protocol>

Returns the first IP protocol segment (Ip4 or Ip6) if present.

Source

pub fn get_dns(&self) -> Option<&Protocol>

Returns the first DNS protocol segment (Dns, Dns4, or Dns6) if present.

Source

pub fn get_identity(&self) -> Option<&Identity>

Returns the first identity segment (NodeId, PeerId, UUID, or Custom) if present.

Source

pub fn resolve(&mut self, ip_addr: IpAddr)

Replace Dns/Dns4/Dns6 protocol with Ip4 or Ip6 This is used to resolve the name to an IP address

Trait Implementations§

Source§

impl Clone for StackAddr

Source§

fn clone(&self) -> StackAddr

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StackAddr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for StackAddr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for StackAddr

Source§

type Err = StackAddrError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for StackAddr

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for StackAddr

Source§

fn cmp(&self, other: &StackAddr) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for StackAddr

Source§

fn eq(&self, other: &StackAddr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for StackAddr

Source§

fn partial_cmp(&self, other: &StackAddr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ToSocketAddrs for StackAddr

Source§

type Iter = IntoIter<SocketAddr>

Returned iterator over socket addresses which this type may correspond to.
Source§

fn to_socket_addrs(&self) -> Result<Self::Iter>

Converts this object to an iterator of resolved SocketAddrs. Read more
Source§

impl Eq for StackAddr

Source§

impl StructuralPartialEq for StackAddr

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.