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§
Sourcefn serialize_into(&self, buffer: &mut [u8]) -> Result<usize, SerializationError>
fn serialize_into(&self, buffer: &mut [u8]) -> Result<usize, SerializationError>
Serialize the key into the given buffer. The serialized size is returned.
Sourcefn deserialize_from(buffer: &[u8]) -> Result<(Self, usize), SerializationError>
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§
Sourcefn get_len(buffer: &[u8]) -> Result<usize, SerializationError>
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.