pub struct Multiaddr { /* private fields */ }
Expand description
Representation of a Multiaddr.
Implementations§
Source§impl 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 libp2prs_multiaddr::{Multiaddr, protocol::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 libp2prs_multiaddr::{Multiaddr, protocol::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 value_for_protocol(&self, code: u32) -> Option<String>
pub fn is_loopback_addr(&self) -> bool
pub fn is_private_addr(&self) -> bool
Sourcepub fn should_consume_fd(&self) -> bool
pub fn should_consume_fd(&self) -> bool
we don’t consume FD’s for relay addresses for now as they will be consumed when the Relay Transport actually dials the Relay server. That dial call will also pass through this limiter with the address of the relay server i.e. non-relay address.
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<'_> ⓘ
pub fn iter(&self) -> Iter<'_> ⓘ
Returns the components of this multiaddress.
§Example
use std::net::Ipv4Addr;
use libp2prs_multiaddr::{Multiaddr, protocol::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>
pub fn replace<'a, F>(&self, at: usize, by: F) -> Option<Multiaddr>
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.