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 Family | Example | Insert<’_> | Borrowed | Clone in iterator? |
|---|---|---|---|---|
| Integer | u64 | u64 | u64 | N |
| Array | [u8; 5] | &'_ [u8; 5] | [u8; 5] | Y |
| Slice | &'a Slice<NonNull> | &'a Slice<NonNull> | Slice<NonNull> | N |
| Boxed Slice | BoxedStr<Terminated<b'\n'>> | &'_ Str<Terminated<b'\n'>> | Str<Terminated<b'\n'>> | Y |
Required Associated Types§
Sourcetype Borrowed: 'static + ?Sized
type Borrowed: 'static + ?Sized
A non-allocated byte sequence that a key can be cheaply borrowed as.
Sourcetype Insert<'k>: Copy + Borrow<Self::Borrowed>
where
Self: 'k
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.
Sourcetype Read<'k>: Read<Edge = Self::Edge, Len = Self::Len> + From<&'k Self::Borrowed>
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.
Required Methods§
Sourcefn insert_as_read<'k>(insert: Self::Insert<'k>) -> Self::Read<'k>where
Self: 'k,
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.
Sourcefn insert_to_key<'k>(insert: Self::Insert<'k>) -> Selfwhere
Self: 'k,
fn insert_to_key<'k>(insert: Self::Insert<'k>) -> Selfwhere
Self: 'k,
Convert the insert type to the key type.
Sourceunsafe fn write_as_insert<'k>(writer: &'k Self::Write) -> Self::Insert<'k>where
Self: 'k,
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".