Trait Key

Source
pub trait Key:
    Eq
    + Clone
    + Sized {
    // Required methods
    fn serialize_into(
        &self,
        buffer: &mut [u8],
    ) -> Result<usize, SerializationError>;
    fn deserialize_from(
        buffer: &[u8],
    ) -> Result<(Self, usize), SerializationError>;

    // Provided method
    fn get_len(buffer: &[u8]) -> Result<usize, SerializationError> { ... }
}
Expand description

Anything implementing this trait can be used as a key in the map functions.

It provides a way to serialize and deserialize the key.

The Eq bound is used because we need to be able to compare keys and the Clone bound helps us pass the key around.

The key cannot have a lifetime like the Value

Required Methods§

Source

fn serialize_into(&self, buffer: &mut [u8]) -> Result<usize, SerializationError>

Serialize the key into the given buffer. The serialized size is returned.

Source

fn deserialize_from(buffer: &[u8]) -> Result<(Self, usize), SerializationError>

Deserialize the key from the given buffer. The key is returned together with the serialized length.

Provided Methods§

Source

fn get_len(buffer: &[u8]) -> Result<usize, SerializationError>

Get the length of the key from the buffer. This is an optimized version of Self::deserialize_from that doesn’t have to deserialize everything.

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§

Source§

impl Key for i8

Source§

impl Key for i16

Source§

impl Key for i32

Source§

impl Key for i64

Source§

impl Key for i128

Source§

impl Key for u8

Source§

impl Key for u16

Source§

impl Key for u32

Source§

impl Key for u64

Source§

impl Key for u128

Source§

impl<const N: usize> Key for [u8; N]

Implementors§