pub struct Multiaddr { /* private fields */ }
Expand description

Representation of a Multiaddr.

Implementations

Returns true if the multiaddres has no data.

Return the length in bytes of this multiaddress.

Return a copy of this Multiaddr’s byte representation.

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

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Convert a Multiaddr to a string

Examples
use tentacle_multiaddr::Multiaddr;

let address: Multiaddr = "/ip4/127.0.0.1/tcp/80".parse().unwrap();
assert_eq!(address.to_string(), "/ip4/127.0.0.1/tcp/80");

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Creates a value from an iterator. Read more

The associated error which can be returned from parsing.

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

Feeds this value into the given Hasher. Read more

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.