Skip to main content

Key

Trait Key 

Source
pub trait Key: Borrow<Self::Borrowed> {
    type Borrowed: 'static + ?Sized;
    type Insert<'k>: Copy + Borrow<Self::Borrowed>
       where Self: 'k;
    type Read<'k>: Read<Edge = Self::Edge, Len = Self::Len> + From<&'k Self::Borrowed>;
    type Write: for<'k> Write<Self::Read<'k>>;
    type Edge: Pack<Packed: Meta> + Send + Sync;
    type Len: Len + From<<Packed<Self::Edge> as Meta>::Len>;

    // Required methods
    fn as_insert(&self) -> Self::Insert<'_>;
    fn insert_as_read<'k>(insert: Self::Insert<'k>) -> Self::Read<'k>
       where Self: 'k;
    fn insert_to_key<'k>(insert: Self::Insert<'k>) -> Self
       where Self: 'k;
    unsafe fn write_as_insert<'k>(writer: &'k Self::Write) -> Self::Insert<'k>
       where Self: 'k;
}
Expand description

Byte sequence that can be stored in an adaptive radix tree.

Must satisfy the prefix property: no key is a prefix of any other key. Fixed-size keys (e.g., u64, [u8; N]) trivially satisfy this property, but dynamically sized keys (slices, boxed slices) require some additional Invariants.

The following table depicts the most relevant key properties for users of this crate. Methods that can insert into the tree take Insert<'_>; other methods take &'_ Borrowed. Using the Iterator API may be expensive for dynamically allocated key types, as they need to be constructed and cloned during traversal; see crate::sequential::Map for workarounds.

Key FamilyExampleInsert<’_>BorrowedClone in iterator?
Integeru64u64u64N
Array[u8; 5]&'_ [u8; 5][u8; 5]Y
Slice&'a Slice<NonNull>&'a Slice<NonNull>Slice<NonNull>N
Boxed SliceBoxedStr<Terminated<b'\n'>>&'_ Str<Terminated<b'\n'>>Str<Terminated<b'\n'>>Y

Required Associated Types§

Source

type Borrowed: 'static + ?Sized

A non-allocated byte sequence that a key can be cheaply borrowed as.

Source

type Insert<'k>: Copy + Borrow<Self::Borrowed> where Self: 'k

Keys can either have edges that store inline bytes (e.g., u64, BoxedSlice), or pointers (i.e., Slice).

The former can take borrowed bytes with any lifetime when inserting, but the latter can only take borrowed bytes that outlive the key type.

Source

type Read<'k>: Read<Edge = Self::Edge, Len = Self::Len> + From<&'k Self::Borrowed>

Tracks key length and allows extracting edges and slicing key bytes.

Source

type Write: for<'k> Write<Self::Read<'k>>

Constructs a key from an initial reader prefix and sequence of bytes and edges.

Source

type Edge: Pack<Packed: Meta> + Send + Sync

Edge metadata.

Source

type Len: Len + From<<Packed<Self::Edge> as Meta>::Len>

Key length.

Required Methods§

Source

fn as_insert(&self) -> Self::Insert<'_>

Convert the key type to the insert type.

Source

fn insert_as_read<'k>(insert: Self::Insert<'k>) -> Self::Read<'k>
where Self: 'k,

Convert the insert type to a reader with appropriate lifetime.

Source

fn insert_to_key<'k>(insert: Self::Insert<'k>) -> Self
where Self: 'k,

Convert the insert type to the key type.

Source

unsafe fn write_as_insert<'k>(writer: &'k Self::Write) -> Self::Insert<'k>
where Self: 'k,

Convert a reference to a writer into the insert type.

§Safety

Caller must guarantee that writer contains a valid key.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Key for u16

Source§

type Read<'k> = Reader<u16>

Source§

type Write = Writer<u16>

Source§

type Borrowed = u16

Source§

type Insert<'k> = u16

Source§

type Edge = Be

Source§

type Len = Bit

Source§

fn as_insert(&self) -> Self::Insert<'_>

Source§

fn insert_as_read<'k>(insert: Self::Insert<'k>) -> Self::Read<'k>
where Self: 'k,

Source§

fn insert_to_key<'k>(insert: Self::Insert<'k>) -> Self
where Self: 'k,

Source§

unsafe fn write_as_insert<'k>(writer: &'k Self::Write) -> Self::Insert<'k>
where Self: 'k,

Source§

impl Key for u32

Source§

type Read<'k> = Reader<u32>

Source§

type Write = Writer<u32>

Source§

type Borrowed = u32

Source§

type Insert<'k> = u32

Source§

type Edge = Be

Source§

type Len = Bit

Source§

fn as_insert(&self) -> Self::Insert<'_>

Source§

fn insert_as_read<'k>(insert: Self::Insert<'k>) -> Self::Read<'k>
where Self: 'k,

Source§

fn insert_to_key<'k>(insert: Self::Insert<'k>) -> Self
where Self: 'k,

Source§

unsafe fn write_as_insert<'k>(writer: &'k Self::Write) -> Self::Insert<'k>
where Self: 'k,

Source§

impl Key for u64

Source§

type Read<'k> = Reader<u64>

Source§

type Write = Writer<u64>

Source§

type Borrowed = u64

Source§

type Insert<'k> = u64

Source§

type Edge = Be

Source§

type Len = Bit

Source§

fn as_insert(&self) -> Self::Insert<'_>

Source§

fn insert_as_read<'k>(insert: Self::Insert<'k>) -> Self::Read<'k>
where Self: 'k,

Source§

fn insert_to_key<'k>(insert: Self::Insert<'k>) -> Self
where Self: 'k,

Source§

unsafe fn write_as_insert<'k>(writer: &'k Self::Write) -> Self::Insert<'k>
where Self: 'k,

Source§

impl Key for u128

Source§

type Read<'k> = Reader<u128>

Source§

type Write = Writer<u128>

Source§

type Borrowed = u128

Source§

type Insert<'k> = u128

Source§

type Edge = Be

Source§

type Len = Bit

Source§

fn as_insert(&self) -> Self::Insert<'_>

Source§

fn insert_as_read<'k>(insert: Self::Insert<'k>) -> Self::Read<'k>
where Self: 'k,

Source§

fn insert_to_key<'k>(insert: Self::Insert<'k>) -> Self
where Self: 'k,

Source§

unsafe fn write_as_insert<'k>(writer: &'k Self::Write) -> Self::Insert<'k>
where Self: 'k,

Source§

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

Source§

type Read<'k> = Reader<'k, N>

Source§

type Write = Writer<N>

Source§

type Borrowed = [u8; N]

Source§

type Insert<'k> = &'k [u8; N]

Source§

type Edge = Le

Source§

type Len = Byte

Source§

fn as_insert(&self) -> Self::Insert<'_>

Source§

fn insert_as_read<'k>(insert: Self::Insert<'k>) -> Self::Read<'k>
where Self: 'k,

Source§

fn insert_to_key<'k>(insert: Self::Insert<'k>) -> Self
where Self: 'k,

Source§

unsafe fn write_as_insert<'k>(writer: &'k Self::Write) -> &'k Self::Borrowed
where Self: 'k,

Implementors§

Source§

impl<'a, I, R> Key for &'a Slice<I, R>
where I: Invariant, R: ?Sized + Raw,

Source§

type Borrowed = Slice<I, R>

Source§

type Insert<'k> = &'a Slice<I, R> where Self: 'k

Source§

type Read<'k> = Reader<'k, <I as Invariant>::Terminate>

Source§

type Write = Writer<I>

Source§

type Edge = Slice<<I as Invariant>::Terminate>

Source§

type Len = Byte

Source§

impl<I, R> Key for BoxedSlice<I, R>
where I: Invariant, R: ?Sized + Raw,

Source§

type Read<'k> = Reader<'k, <I as Invariant>::Terminate>

Source§

type Write = Writer

Source§

type Borrowed = Slice<I, R>

Source§

type Insert<'k> = &'k Slice<I, R>

Source§

type Edge = Le

Source§

type Len = Byte