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
impl PeerId
sourcepub fn to_safe(&self) -> Cow<'_, str>
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§
impl Copy for PeerId
Auto Trait Implementations§
impl RefUnwindSafe for PeerId
impl Send for PeerId
impl Sync for PeerId
impl Unpin for PeerId
impl UnwindSafe for PeerId
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