pub struct Multiaddr { /* private fields */ }
Expand description
Representation of a Multiaddr.
Implementations
sourceimpl Multiaddr
impl Multiaddr
sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Create a new, empty multiaddress with the given capacity.
sourcepub fn push(&mut self, p: Protocol<'_>)
pub fn push(&mut self, p: Protocol<'_>)
Adds an already-parsed address component to the end of this multiaddr.
Examples
use multiaddr::{Multiaddr, Protocol};
let mut address: Multiaddr = "/ip4/127.0.0.1".parse().unwrap();
address.push(Protocol::Tcp(10000));
assert_eq!(address, "/ip4/127.0.0.1/tcp/10000".parse().unwrap());
sourcepub fn pop<'a>(&mut self) -> Option<Protocol<'a>>
pub fn pop<'a>(&mut self) -> Option<Protocol<'a>>
Pops the last Protocol
of this multiaddr, or None
if the multiaddr is empty.
use multiaddr::{Multiaddr, Protocol};
let mut address: Multiaddr = "/ip4/127.0.0.1/udt/sctp/5678".parse().unwrap();
assert_eq!(address.pop().unwrap(), Protocol::Sctp(5678));
assert_eq!(address.pop().unwrap(), Protocol::Udt);
sourcepub fn with(self, p: Protocol<'_>) -> Self
pub fn with(self, p: Protocol<'_>) -> Self
Like Multiaddr::push
but consumes self
.
sourcepub fn iter(&self) -> Iter<'_>ⓘNotable traits for Iter<'a>impl<'a> Iterator for Iter<'a> type Item = Protocol<'a>;
pub fn iter(&self) -> Iter<'_>ⓘNotable traits for Iter<'a>impl<'a> Iterator for Iter<'a> type Item = Protocol<'a>;
Returns the components of this multiaddress.
Example
use std::net::Ipv4Addr;
use multiaddr::{Multiaddr, Protocol};
let address: Multiaddr = "/ip4/127.0.0.1/udt/sctp/5678".parse().unwrap();
let components = address.iter().collect::<Vec<_>>();
assert_eq!(components[0], Protocol::Ip4(Ipv4Addr::new(127, 0, 0, 1)));
assert_eq!(components[1], Protocol::Udt);
assert_eq!(components[2], Protocol::Sctp(5678));
sourcepub fn replace<'a, F>(&self, at: usize, by: F) -> Option<Multiaddr>where
F: FnOnce(&Protocol<'_>) -> Option<Protocol<'a>>,
pub fn replace<'a, F>(&self, at: usize, by: F) -> Option<Multiaddr>where
F: FnOnce(&Protocol<'_>) -> Option<Protocol<'a>>,
Replace a Protocol
at some position in this Multiaddr
.
The parameter at
denotes the index of the protocol at which the function
by
will be applied to the current protocol, returning an optional replacement.
If at
is out of bounds or by
does not yield a replacement value,
None
will be returned. Otherwise a copy of this Multiaddr
with the
updated Protocol
at position at
will be returned.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Multiaddr
impl<'de> Deserialize<'de> for Multiaddr
sourcefn deserialize<D>(deserializer: D) -> StdResult<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> StdResult<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<'a> FromIterator<Protocol<'a>> for Multiaddr
impl<'a> FromIterator<Protocol<'a>> for Multiaddr
sourcefn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = Protocol<'a>>,
fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = Protocol<'a>>,
Creates a value from an iterator. Read more
sourceimpl<'a> IntoIterator for &'a Multiaddr
impl<'a> IntoIterator for &'a Multiaddr
sourceimpl Ord for Multiaddr
impl Ord for Multiaddr
1.21.0 · sourceconst fn max(self, other: Self) -> Self
const fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourceconst fn min(self, other: Self) -> Self
const fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourceconst fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
const fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialOrd<Multiaddr> for Multiaddr
impl PartialOrd<Multiaddr> for Multiaddr
sourcefn partial_cmp(&self, other: &Multiaddr) -> Option<Ordering>
fn partial_cmp(&self, other: &Multiaddr) -> Option<Ordering>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Eq for Multiaddr
impl StructuralEq for Multiaddr
impl StructuralPartialEq for Multiaddr
Auto Trait Implementations
impl RefUnwindSafe for Multiaddr
impl Send for Multiaddr
impl Sync for Multiaddr
impl Unpin for Multiaddr
impl UnwindSafe for Multiaddr
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more