Enum zeronet_protocol::address::PeerAddr [−][src]
Variants
Implementations
Create an address by parsing a string
use zeronet_protocol::PeerAddr; let address = PeerAddr::parse("127.0.0.1:8001").unwrap(); assert!(address.is_clearnet());
Unpack the address from bytes
use zeronet_protocol::PeerAddr; let bytes = vec![127, 0, 0, 1, 225, 16]; let address = PeerAddr::unpack(&bytes).unwrap(); assert_eq!(address.to_string(), "127.0.0.1:4321".to_string());
Pack the address into bytes
use zeronet_protocol::PeerAddr; let address = PeerAddr::parse("127.0.0.1:4321").expect("could not parse address"); let packed = address.pack(); assert_eq!(packed, [127, 0, 0, 1, 225, 16]);
To string
use zeronet_protocol::PeerAddr; let address = PeerAddr::parse("127.0.0.1:4321").unwrap(); assert_eq!(address.to_string(), "127.0.0.1:4321".to_string());
Change the port of the address.
use zeronet_protocol::PeerAddr; let address = PeerAddr::parse("127.0.0.1:4321").unwrap(); let address = address.with_port(1234); assert_eq!(address.to_string(), "127.0.0.1:1234".to_string());
Trait Implementations
Performs the conversion.
to_peer_addr
use zeronet_protocol::{ToPeerAddrs, PeerAddr}; let peer_addr = PeerAddr::parse("127.0.0.1:4321").unwrap(); assert!(peer_addr.to_peer_addrs().is_ok()); assert!(peer_addr.to_peer_addrs().unwrap().len() == 1);
type Error = AddressError
type Error = AddressError
The type returned in the event of a conversion error.
Performs the conversion.
type Error = AddressError
type Error = AddressError
The type returned in the event of a conversion error.
Performs the conversion.
Auto Trait Implementations
impl RefUnwindSafe for PeerAddr
impl UnwindSafe for PeerAddr
Blanket Implementations
Mutably borrows from an owned value. Read more