pub struct Id(/* private fields */);Expand description
Kademlia node Id or a lookup target
Implementations§
Source§impl Id
impl Id
Sourcepub fn from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Id, InvalidIdSize>
pub fn from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Id, InvalidIdSize>
Create a new Id from some bytes. Returns Err if the input is not 20 bytes long.
Sourcepub fn distance(&self, other: &Id) -> u8
pub fn distance(&self, other: &Id) -> u8
Simplified XOR distance between this Id and a target Id.
The distance is the number of trailing non zero bits in the XOR result.
Distance to self is 0 Distance to the furthest Id is 160 Distance to an Id with 5 leading matching bits is 155
Sourcepub fn leading_zeros(&self) -> u8
pub fn leading_zeros(&self) -> u8
Returns the number of leading zeros in the binary representation of self.
Sourcepub fn from_addr(addr: &SocketAddr) -> Id
pub fn from_addr(addr: &SocketAddr) -> Id
Create a new Id according to BEP_0042.
Sourcepub fn from_ipv4(ipv4: Ipv4Addr) -> Id
pub fn from_ipv4(ipv4: Ipv4Addr) -> Id
Create a new Id from an Ipv4 address according to BEP_0042.
Sourcepub fn is_valid_for_ip(&self, ipv4: Ipv4Addr) -> bool
pub fn is_valid_for_ip(&self, ipv4: Ipv4Addr) -> bool
Validate that this Id is valid with respect to BEP_0042.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Id
impl<'de> Deserialize<'de> for Id
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Id
impl Ord for Id
Source§impl PartialOrd for Id
impl PartialOrd for Id
impl Copy for Id
impl Eq for Id
impl StructuralPartialEq for Id
Auto Trait Implementations§
impl Freeze for Id
impl RefUnwindSafe for Id
impl Send for Id
impl Sync for Id
impl Unpin for Id
impl UnwindSafe for Id
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more