Struct tdyne_peer_id::PeerId

source ·
#[repr(transparent)]
pub struct PeerId(pub [u8; 20]);
Expand description

Represents an unparsed peer ID. It’s just a thin wrapper over [u8; 20].

Tuple Fields§

§0: [u8; 20]

Implementations§

source§

impl PeerId

source

pub fn to_safe(&self) -> Cow<'_, str>

Renders the PeerId into a Cow<'_, str> with every character outside base64 range (0-9, a-z, A-Z, -, .) transformed into ASCII ?. Most clients only use those characters in their peer IDs, so this representation is good enough, while being completely safe to show in any environment without escaping.

Returns Cow<'_, str> despite always allocating the string at the moment in anticipation of a future optimisation.

Reused in the Display implementation.

let peer_id = PeerId::from(b"-TR0000-*\x00\x01d7xkqq04n");
assert_eq!(peer_id.to_safe(), "-TR0000-???d7xkqq04n");

Trait Implementations§

source§

impl AsRef<[u8; 20]> for PeerId

source§

fn as_ref(&self) -> &[u8; 20]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for PeerId

source§

fn clone(&self) -> PeerId

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PeerId

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for PeerId

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&[u8; 20]> for PeerId

source§

fn from(value: &[u8; 20]) -> Self

Converts to this type from the input type.
source§

impl From<[u8; 20]> for PeerId

source§

fn from(value: [u8; 20]) -> Self

Converts to this type from the input type.
source§

impl TryFrom<&[u8]> for PeerId

§

type Error = BadPeerIdLengthError

The type returned in the event of a conversion error.
source§

fn try_from(value: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for PeerId

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.