pub struct Id20(pub [u8; 20]);Expand description
20-byte identifier used for SHA1 info-hashes and peer IDs.
Tuple Fields§
§0: [u8; 20]Implementations§
Source§impl Id20
impl Id20
Sourcepub fn from_hex(s: &str) -> Result<Self, Error>
pub fn from_hex(s: &str) -> Result<Self, Error>
Create from a hex string (40 chars).
§Errors
Returns an error if the string is not valid hex or has the wrong length.
Sourcepub fn from_base32(s: &str) -> Result<Self, Error>
pub fn from_base32(s: &str) -> Result<Self, Error>
Create from a base32 string (32 chars, used in magnet links).
§Errors
Returns an error if the string is not valid base32 or has the wrong length.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
Create from a byte slice, validating length.
§Errors
Returns an error if the byte slice is not exactly 20 bytes.
Sourcepub fn xor_distance(&self, other: &Self) -> Self
pub fn xor_distance(&self, other: &Self) -> Self
XOR distance to another Id20 (used in DHT/Kademlia).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Id20
impl<'de> Deserialize<'de> for Id20
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Id20
impl Ord for Id20
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Id20
impl PartialOrd for Id20
impl Copy for Id20
impl Eq for Id20
impl StructuralPartialEq for Id20
Auto Trait Implementations§
impl Freeze for Id20
impl RefUnwindSafe for Id20
impl Send for Id20
impl Sync for Id20
impl Unpin for Id20
impl UnsafeUnpin for Id20
impl UnwindSafe for Id20
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<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self into the result. Upper case
letters are used (e.g. F9B4CA)