pub struct Key { /* private fields */ }
Expand description
DHT key type with proper Kademlia distance calculation
Implementations§
Source§impl Key
impl Key
Sourcepub fn distance(&self, other: &Key) -> Key
pub fn distance(&self, other: &Key) -> Key
Calculate XOR distance between two keys (Kademlia distance metric)
Sourcepub fn leading_zeros(&self) -> u32
pub fn leading_zeros(&self) -> u32
Get the bit length of the distance (number of leading zeros)
Sourcepub fn bucket_index(&self, local_id: &Key) -> usize
pub fn bucket_index(&self, local_id: &Key) -> usize
Get bucket index for this key relative to local node
Source§impl Key
impl Key
Sourcepub fn from_inbox_id(inbox_id: &str) -> Self
pub fn from_inbox_id(inbox_id: &str) -> Self
Create a key for inbox metadata
Sourcepub fn from_inbox_index(inbox_id: &str) -> Self
pub fn from_inbox_index(inbox_id: &str) -> Self
Create a key for inbox message index
Sourcepub fn from_inbox_message(inbox_id: &str, message_id: &str) -> Self
pub fn from_inbox_message(inbox_id: &str, message_id: &str) -> Self
Create a key for a specific message in an inbox
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Key
impl<'de> Deserialize<'de> for Key
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
impl Eq for Key
impl StructuralPartialEq for Key
Auto Trait Implementations§
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnwindSafe for Key
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.