Enum zeronet_protocol::address::PeerAddr
source · [−]Variants
IPV4([u8; 4], u16)
IPV6([u8; 16], u16)
Implementations
sourceimpl PeerAddr
impl PeerAddr
sourcepub fn parse<S: Into<String>>(address: S) -> Result<PeerAddr, ParseError>
pub fn parse<S: Into<String>>(address: S) -> Result<PeerAddr, ParseError>
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());
sourcepub fn unpack(bytes: &[u8]) -> Result<PeerAddr, AddressError>
pub fn unpack(bytes: &[u8]) -> Result<PeerAddr, AddressError>
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());
sourcepub fn pack(&self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn pack(&self) -> Vec<u8>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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]);
sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
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());
pub fn get_pair(
&self
) -> Result<(Box<dyn Read + Send>, Box<dyn Write + Send>), AddressError>
sourcepub fn with_port(&self, port: u16) -> PeerAddr
pub fn with_port(&self, port: u16) -> PeerAddr
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());
pub fn get_port(&self) -> u16
pub fn is_clearnet(&self) -> bool
Trait Implementations
sourceimpl From<SocketAddr> for PeerAddr
impl From<SocketAddr> for PeerAddr
sourcefn from(address: SocketAddr) -> PeerAddr
fn from(address: SocketAddr) -> PeerAddr
Converts to this type from the input type.
sourceimpl ToPeerAddrs for PeerAddr
impl ToPeerAddrs for PeerAddr
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);
sourceimpl TryInto<SocketAddr> for PeerAddr
impl TryInto<SocketAddr> for PeerAddr
type Error = AddressError
type Error = AddressError
The type returned in the event of a conversion error.
sourcefn try_into(self) -> Result<SocketAddr, Self::Error>
fn try_into(self) -> Result<SocketAddr, Self::Error>
Performs the conversion.
sourceimpl TryInto<SocketAddr> for &PeerAddr
impl TryInto<SocketAddr> for &PeerAddr
type Error = AddressError
type Error = AddressError
The type returned in the event of a conversion error.
sourcefn try_into(self) -> Result<SocketAddr, Self::Error>
fn try_into(self) -> Result<SocketAddr, Self::Error>
Performs the conversion.
impl Eq for PeerAddr
impl StructuralEq for PeerAddr
impl StructuralPartialEq for PeerAddr
Auto Trait Implementations
impl RefUnwindSafe for PeerAddr
impl Send for PeerAddr
impl Sync for PeerAddr
impl Unpin for PeerAddr
impl UnwindSafe for PeerAddr
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more