Skip to main content

Key

Trait Key 

Source
pub trait Key:
    Sized
    + Ord
    + Clone
    + Debug
    + Default
    + Max
    + Min {
    const SERIALIZED_SIZE: usize;

    // Required methods
    fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize>;
    fn read_from<R: Read>(reader: &mut R) -> Result<Self>;
    fn from_bytes(bytes: &[u8]) -> Result<Self>;
}
Expand description

Trait defining requirements for keys used in the StaticBTree.

Keys must support ordering (Ord), cloning (Clone), debugging (Debug), and have a fixed serialized size (SERIALIZED_SIZE). Variable-length types like String must be adapted (e.g., using fixed-size prefixes) to conform.

Required Associated Constants§

Source

const SERIALIZED_SIZE: usize

The exact size of the key in bytes when serialized. This is crucial for calculating node sizes and offsets.

Required Methods§

Source

fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize>

Serializes the key into the provided writer.

§Arguments
  • writer: The Write target.
§Returns

Returns the number of bytes written, which is always SERIALIZED_SIZE Err(Error) if writing fails.

Source

fn read_from<R: Read>(reader: &mut R) -> Result<Self>

Deserializes a key from the provided reader.

§Arguments
  • reader: The Read source.
§Returns

Ok(Self) containing the deserialized key on success. Err(Error) if reading fails or the implementation cannot read exactly SERIALIZED_SIZE bytes.

Source

fn from_bytes(bytes: &[u8]) -> Result<Self>

Deserializes a key from the provided bytes.

§Arguments
  • bytes: The bytes to deserialize the key from.
§Returns

Ok(Self) containing the deserialized key on success. Err(Error) if the bytes are not a valid key.

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 bool

Source§

const SERIALIZED_SIZE: usize = 1

Source§

fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize>

Source§

fn read_from<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

impl Key for i8

Source§

const SERIALIZED_SIZE: usize

Source§

fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize>

Source§

fn read_from<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

impl Key for i16

Source§

const SERIALIZED_SIZE: usize

Source§

fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize>

Source§

fn read_from<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

impl Key for i32

Source§

const SERIALIZED_SIZE: usize

Source§

fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize>

Source§

fn read_from<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

impl Key for i64

Source§

const SERIALIZED_SIZE: usize

Source§

fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize>

Source§

fn read_from<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

impl Key for u8

Source§

const SERIALIZED_SIZE: usize

Source§

fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize>

Source§

fn read_from<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

impl Key for u16

Source§

const SERIALIZED_SIZE: usize

Source§

fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize>

Source§

fn read_from<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

impl Key for u32

Source§

const SERIALIZED_SIZE: usize

Source§

fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize>

Source§

fn read_from<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

impl Key for u64

Source§

const SERIALIZED_SIZE: usize

Source§

fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize>

Source§

fn read_from<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Source§

impl Key for DateTime<Utc>

Source§

const SERIALIZED_SIZE: usize = 12

Source§

fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize>

Source§

fn read_from<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn from_bytes(bytes: &[u8]) -> Result<Self>

Implementors§