Struct tentacle_multiaddr::Multiaddr [−][src]
pub struct Multiaddr { /* fields omitted */ }Expand description
Representation of a Multiaddr.
Implementations
Adds an already-parsed address component to the end of this multiaddr.
Examples
use tentacle_multiaddr::{Multiaddr, Protocol};
let mut address: Multiaddr = "/ip4/127.0.0.1".parse().unwrap();
address.push(Protocol::Tcp(10000));
println!("{}", address);
assert_eq!(address, "/ip4/127.0.0.1/tcp/10000".parse().unwrap());Pops the last Protocol of this multiaddr, or None if the multiaddr is empty.
use std::net::Ipv4Addr;
use tentacle_multiaddr::{Multiaddr, Protocol};
let mut address: Multiaddr = "/ip4/127.0.0.1/tcp/5678".parse().unwrap();
assert_eq!(address.pop().unwrap(), Protocol::Tcp(5678));
assert_eq!(address.pop().unwrap(), Protocol::Ip4(Ipv4Addr::new(127, 0, 0, 1)));Returns the components of this multiaddress.
use std::net::Ipv4Addr;
use tentacle_multiaddr::{Multiaddr, Protocol};
let address: Multiaddr = "/ip4/127.0.0.1/tcp/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::Tcp(5678));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
Deserialize this value from the given Serde deserializer. Read more
Creates a value from an iterator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Multiaddr
impl UnwindSafe for Multiaddr
Blanket Implementations
Mutably borrows from an owned value. Read more
