Skip to main content

KeyBytes

Struct KeyBytes 

Source
#[repr(transparent)]
pub struct KeyBytes<const LEN: usize>(pub [u8; LEN]);
Expand description

Generic wrapper for a fixed-length array of cryptographic key bytes, convertible to or from a base58-encoded string.

Tuple Fields§

§0: [u8; LEN]

Implementations§

Source§

impl<const LEN: usize> KeyBytes<LEN>

Source

pub fn new(bytes: [u8; LEN]) -> KeyBytes<LEN>

Construct a new instance from the provided key bytes

Source

pub fn into_bytes(self) -> [u8; LEN]

Return the public key bytes contained in this instance

Source

pub fn try_from_ref<T>(key: T) -> Result<KeyBytes<LEN>, TryFromSliceError>
where T: AsRef<[u8]>,

Attempt to convert the provided byte slice to a new key byte array

§Errors

This function returns an error if calling KeyBytes::try_from(slice) returns an error.

Source

pub fn equals_ref<T>(&self, other: T) -> bool
where T: AsRef<[u8]>,

Compare the public key bytes contained in this array with the given byte slice

Trait Implementations§

Source§

impl<const LEN: usize> AsMut<[u8]> for KeyBytes<LEN>

Source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<const LEN: usize> AsMut<[u8; LEN]> for KeyBytes<LEN>

Source§

fn as_mut(&mut self) -> &mut [u8; LEN]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<const LEN: usize> AsRef<[u8]> for KeyBytes<LEN>

Source§

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

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

impl<const LEN: usize> AsRef<[u8; LEN]> for KeyBytes<LEN>

Source§

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

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

impl<const LEN: usize> Borrow<[u8]> for KeyBytes<LEN>

Source§

fn borrow(&self) -> &[u8]

Immutably borrows from an owned value. Read more
Source§

impl<const LEN: usize> Borrow<[u8; LEN]> for KeyBytes<LEN>

Source§

fn borrow(&self) -> &[u8; LEN]

Immutably borrows from an owned value. Read more
Source§

impl<const LEN: usize> BorrowMut<[u8]> for KeyBytes<LEN>

Source§

fn borrow_mut(&mut self) -> &mut [u8]

Mutably borrows from an owned value. Read more
Source§

impl<const LEN: usize> BorrowMut<[u8; LEN]> for KeyBytes<LEN>

Source§

fn borrow_mut(&mut self) -> &mut [u8; LEN]

Mutably borrows from an owned value. Read more
Source§

impl<const LEN: usize> BorshDeserialize for KeyBytes<LEN>

Source§

fn deserialize_reader<R>(reader: &mut R) -> Result<KeyBytes<LEN>, Error>
where R: Read,

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl<const LEN: usize> BorshSerialize for KeyBytes<LEN>

Source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write,

Source§

impl<const LEN: usize> Clone for KeyBytes<LEN>

Source§

fn clone(&self) -> KeyBytes<LEN>

Returns a duplicate 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<const LEN: usize> Debug for KeyBytes<LEN>

Source§

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

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

impl<const LEN: usize> Default for KeyBytes<LEN>

Source§

fn default() -> KeyBytes<LEN>

Returns the “default value” for a type. Read more
Source§

impl<const LEN: usize> Deref for KeyBytes<LEN>

Source§

type Target = [u8; LEN]

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<KeyBytes<LEN> as Deref>::Target

Dereferences the value.
Source§

impl<const LEN: usize> DerefMut for KeyBytes<LEN>

Source§

fn deref_mut(&mut self) -> &mut <KeyBytes<LEN> as Deref>::Target

Mutably dereferences the value.
Source§

impl<const LEN: usize> Display for KeyBytes<LEN>

Source§

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

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

impl<const LEN: usize> From<[u8; LEN]> for KeyBytes<LEN>

Source§

fn from(value: [u8; LEN]) -> KeyBytes<LEN>

Converts to this type from the input type.
Source§

impl<const LEN: usize> From<KeyBytes<LEN>> for [u8; LEN]

Source§

fn from(value: KeyBytes<LEN>) -> [u8; LEN]

Converts to this type from the input type.
Source§

impl<const LEN: usize> FromStr for KeyBytes<LEN>

Source§

type Err = KeyFromStrError<LEN>

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<KeyBytes<LEN>, <KeyBytes<LEN> as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<const LEN: usize> Hash for KeyBytes<LEN>

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const LEN: usize> PartialEq for KeyBytes<LEN>

Source§

fn eq(&self, other: &KeyBytes<LEN>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const LEN: usize> TryFrom<&[u8]> for KeyBytes<LEN>

Source§

type Error = TryFromSliceError

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

fn try_from( value: &[u8], ) -> Result<KeyBytes<LEN>, <KeyBytes<LEN> as TryFrom<&[u8]>>::Error>

Performs the conversion.
Source§

impl<const LEN: usize> TryFrom<&str> for KeyBytes<LEN>

Source§

type Error = KeyFromStrError<LEN>

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

fn try_from( value: &str, ) -> Result<KeyBytes<LEN>, <KeyBytes<LEN> as TryFrom<&str>>::Error>

Performs the conversion.
Source§

impl<const LEN: usize> TryFrom<Cow<'_, str>> for KeyBytes<LEN>

Source§

type Error = KeyFromStrError<LEN>

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

fn try_from( value: Cow<'_, str>, ) -> Result<KeyBytes<LEN>, <KeyBytes<LEN> as TryFrom<Cow<'_, str>>>::Error>

Performs the conversion.
Source§

impl<const LEN: usize> TryFrom<String> for KeyBytes<LEN>

Source§

type Error = KeyFromStrError<LEN>

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

fn try_from( value: String, ) -> Result<KeyBytes<LEN>, <KeyBytes<LEN> as TryFrom<String>>::Error>

Performs the conversion.
Source§

impl<const LEN: usize> Copy for KeyBytes<LEN>

Source§

impl<const LEN: usize> Eq for KeyBytes<LEN>

Source§

impl<const LEN: usize> StructuralPartialEq for KeyBytes<LEN>

Auto Trait Implementations§

§

impl<const LEN: usize> Freeze for KeyBytes<LEN>

§

impl<const LEN: usize> RefUnwindSafe for KeyBytes<LEN>

§

impl<const LEN: usize> Send for KeyBytes<LEN>

§

impl<const LEN: usize> Sync for KeyBytes<LEN>

§

impl<const LEN: usize> Unpin for KeyBytes<LEN>

§

impl<const LEN: usize> UnsafeUnpin for KeyBytes<LEN>

§

impl<const LEN: usize> UnwindSafe for KeyBytes<LEN>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.