Struct libp2p_core::Multiaddr [−][src]
pub struct Multiaddr { /* fields omitted */ }Representation of a Multiaddr.
Implementations
impl Multiaddr[src]
impl Multiaddr[src]pub fn empty() -> Multiaddr[src]
Create a new, empty multiaddress.
pub fn with_capacity(n: usize) -> Multiaddr[src]
Create a new, empty multiaddress with the given capacity.
pub fn len(&self) -> usize[src]
Return the length in bytes of this multiaddress.
pub fn is_empty(&self) -> bool[src]
Returns true if the length of this multiaddress is 0.
pub fn to_vec(&self) -> Vec<u8, Global>[src]
Return a copy of this Multiaddr’s byte representation.
pub fn push(&mut self, p: Protocol<'_>)[src]
Adds an already-parsed address component to the end of this multiaddr.
Examples
use parity_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());
pub fn pop<'a>(&mut self) -> Option<Protocol<'a>>[src]
Pops the last Protocol of this multiaddr, or None if the multiaddr is empty.
use parity_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);
pub fn with(self, p: Protocol<'_>) -> Multiaddr[src]
Like Multiaddr::push but consumes self.
pub fn iter(&self) -> Iter<'_>[src]
Returns the components of this multiaddress.
Example
use std::net::Ipv4Addr; use parity_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));
pub fn replace<'a, F>(&self, at: usize, by: F) -> Option<Multiaddr> where
F: FnOnce(&Protocol<'_>) -> Option<Protocol<'a>>, [src]
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.
pub fn ends_with(&self, other: &Multiaddr) -> bool[src]
Checks whether the given Multiaddr is a suffix of this Multiaddr.
Trait Implementations
impl<'de> Deserialize<'de> for Multiaddr[src]
impl<'de> Deserialize<'de> for Multiaddr[src]pub fn deserialize<D>(
deserializer: D
) -> Result<Multiaddr, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>, [src]
deserializer: D
) -> Result<Multiaddr, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
impl<'a> FromIterator<Protocol<'a>> for Multiaddr[src]
impl<'a> FromIterator<Protocol<'a>> for Multiaddr[src]pub fn from_iter<T>(iter: T) -> Multiaddr where
T: IntoIterator<Item = Protocol<'a>>, [src]
T: IntoIterator<Item = Protocol<'a>>,
impl<'a> IntoIterator for &'a Multiaddr[src]
impl<'a> IntoIterator for &'a Multiaddr[src]impl PartialOrd<Multiaddr> for Multiaddr[src]
impl PartialOrd<Multiaddr> for Multiaddr[src]pub fn partial_cmp(&self, other: &Multiaddr) -> Option<Ordering>[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool1.0.0[src]
impl Serialize for Multiaddr[src]
impl Serialize for Multiaddr[src]pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer, [src]
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,