Trait ByteArray

pub trait ByteArray<const N: usize>:
    Sized
    + Copy
    + Debug
    + Eq
    + Hash {
    // Required methods
    fn from_array(array: [u8; N]) -> Self;
    fn to_array(&self) -> [u8; N];
    fn as_array(&self) -> &[u8; N];

    // Provided methods
    fn as_slice(&self) -> &[u8]  { ... }
    fn to_vec(&self) -> Vec<u8>  { ... }
    fn try_from_slice(slice: &[u8]) -> Result<Self, TryFromSliceError> { ... }
    fn try_from_vec(vec: Vec<u8>) -> Result<Self, TryFromSliceError> { ... }
    fn from_hex(s: &str) -> Result<Self, DecodeError> { ... }
    fn to_hex(&self) -> String { ... }
    fn as_hex_display(&self) -> HexDisplay<'_> { ... }
    fn fmt_as_hex(&self, f: &mut Formatter<'_>) -> Result<(), Error> { ... }
}
Expand description

A trait for types represented in memory as a byte array. Should NOT be implemented for types that require validation of the byte array contents.

Required Methods§

fn from_array(array: [u8; N]) -> Self

fn to_array(&self) -> [u8; N]

fn as_array(&self) -> &[u8; N]

Provided Methods§

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

fn to_vec(&self) -> Vec<u8>

fn try_from_slice(slice: &[u8]) -> Result<Self, TryFromSliceError>

fn try_from_vec(vec: Vec<u8>) -> Result<Self, TryFromSliceError>

fn from_hex(s: &str) -> Result<Self, DecodeError>

fn to_hex(&self) -> String

fn as_hex_display(&self) -> HexDisplay<'_>

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl ByteArray<4> for MrShort

§

fn from_array(array: [u8; 4]) -> MrShort

§

fn to_array(&self) -> [u8; 4]

§

fn as_array(&self) -> &[u8; 4]

§

impl ByteArray<4> for ShortUserPk

§

fn from_array(array: [u8; 4]) -> ShortUserPk

§

fn to_array(&self) -> [u8; 4]

§

fn as_array(&self) -> &[u8; 4]

§

impl ByteArray<16> for LxUserChannelId

§

fn from_array(array: [u8; 16]) -> LxUserChannelId

§

fn to_array(&self) -> [u8; 16]

§

fn as_array(&self) -> &[u8; 16]

§

impl ByteArray<16> for MachineId

§

fn from_array(array: [u8; 16]) -> MachineId

§

fn to_array(&self) -> [u8; 16]

§

fn as_array(&self) -> &[u8; 16]

§

impl ByteArray<32> for Hash

§

fn from_array(array: [u8; 32]) -> Hash

§

fn to_array(&self) -> [u8; 32]

§

fn as_array(&self) -> &[u8; 32]

§

impl ByteArray<32> for LxChannelId

§

fn from_array(array: [u8; 32]) -> LxChannelId

§

fn to_array(&self) -> [u8; 32]

§

fn as_array(&self) -> &[u8; 32]

§

impl ByteArray<32> for Measurement

§

fn from_array(array: [u8; 32]) -> Measurement

§

fn to_array(&self) -> [u8; 32]

§

fn as_array(&self) -> &[u8; 32]

§

impl ByteArray<32> for NostrEventId

§

fn from_array(array: [u8; 32]) -> NostrEventId

§

fn to_array(&self) -> [u8; 32]

§

fn as_array(&self) -> &[u8; 32]

§

impl ByteArray<32> for NostrPk

§

fn from_array(array: [u8; 32]) -> NostrPk

§

fn to_array(&self) -> [u8; 32]

§

fn as_array(&self) -> &[u8; 32]

§

impl ByteArray<32> for NostrSk

§

fn from_array(array: [u8; 32]) -> NostrSk

§

fn to_array(&self) -> [u8; 32]

§

fn as_array(&self) -> &[u8; 32]

§

impl ByteArray<32> for OfferId

§

fn from_array(array: [u8; 32]) -> OfferId

§

fn to_array(&self) -> [u8; 32]

§

fn as_array(&self) -> &[u8; 32]

§

impl ByteArray<32> for PaymentPreimage

§

fn from_array(array: [u8; 32]) -> PaymentPreimage

§

fn to_array(&self) -> [u8; 32]

§

fn as_array(&self) -> &[u8; 32]

§

impl ByteArray<32> for UserPk

§

fn from_array(array: [u8; 32]) -> UserPk

§

fn to_array(&self) -> [u8; 32]

§

fn as_array(&self) -> &[u8; 32]

Implementors§

Source§

impl ByteArray<32> for lexe::types::auth::Measurement

Source§

impl ByteArray<32> for lexe::types::auth::UserPk

§

impl ByteArray<32> for ClientPaymentId

§

impl ByteArray<32> for LnClaimId

§

impl ByteArray<32> for PaymentHash

§

impl ByteArray<32> for PaymentSecret