pub struct Id32(pub [u8; 32]);Expand description
32-byte identifier used for SHA-256 (BitTorrent v2).
Tuple Fields§
§0: [u8; 32]Implementations§
Source§impl Id32
impl Id32
Sourcepub fn from_hex(s: &str) -> Result<Self, Error>
pub fn from_hex(s: &str) -> Result<Self, Error>
Create from a hex string (64 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 (used in v2 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 32 bytes.
Sourcepub fn to_base32(&self) -> String
pub fn to_base32(&self) -> String
Encode as base32 string (no padding), used in v2 magnet links.
Sourcepub fn to_multihash_hex(&self) -> String
pub fn to_multihash_hex(&self) -> String
Encode as multihash hex string for BEP 52 magnet URIs (urn:btmh:).
Format: 1220 prefix (SHA-256 function code + 32-byte length) + 64 hex chars.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Id32
impl<'de> Deserialize<'de> for Id32
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 Id32
impl Ord for Id32
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 Id32
impl PartialOrd for Id32
impl Copy for Id32
impl Eq for Id32
impl StructuralPartialEq for Id32
Auto Trait Implementations§
impl Freeze for Id32
impl RefUnwindSafe for Id32
impl Send for Id32
impl Sync for Id32
impl Unpin for Id32
impl UnsafeUnpin for Id32
impl UnwindSafe for Id32
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)