mod discard;
mod len;
mod sized;
mod r#unsized;
pub(crate) use discard::Discard;
pub(crate) use len::Bit;
pub(crate) use len::Byte;
pub(crate) use len::Len;
#[cfg_attr(not(feature = "smr-hazard"), expect(unused))]
pub(crate) use sized::unsigned;
pub(crate) use r#unsized::Terminate;
pub(crate) use r#unsized::boxed_slice;
#[cfg_attr(not(feature = "smr-hazard"), expect(unused))]
pub(crate) use r#unsized::slice;
pub use r#unsized::Invariant;
pub use r#unsized::NonNull;
pub use r#unsized::Terminated;
pub use r#unsized::boxed_slice::BoxedSlice;
pub use r#unsized::slice::Slice;
pub type Str<I> = Slice<I, str>;
pub type BoxedStr<I> = BoxedSlice<I, str>;
use core::borrow::Borrow;
use core::fmt;
use crate::raw::edge;
use crate::raw::edge::Meta as _;
pub trait Key: Borrow<Self::Borrowed> {
type Borrowed: 'static + ?Sized;
type Insert<'k>: Copy + Borrow<Self::Borrowed>
where
Self: 'k;
#[expect(private_bounds)]
type Read<'k>: Read<Edge = Self::Edge, Len = Self::Len> + From<&'k Self::Borrowed>;
#[expect(private_bounds)]
type Write: for<'k> Write<Self::Read<'k>>;
#[expect(private_bounds)]
type Edge: ribbit::Pack<Packed: edge::Meta> + Send + Sync;
#[expect(private_bounds)]
type Len: Len + From<<ribbit::Packed<Self::Edge> as edge::Meta>::Len>;
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;
}
pub trait Split: Key {
fn split_last<'k>(key: &'k Self::Borrowed) -> (Self::Read<'k>, u8);
}
pub(crate) trait Read: Copy + fmt::Debug + Default + Eq {
const LEN: Option<Self::Len>;
type Edge: ribbit::Pack<Packed: edge::Meta>;
type Len: Len
+ From<<ribbit::Packed<Self::Edge> as edge::Meta>::Len>
+ Into<<ribbit::Packed<Self::Edge> as edge::Meta>::Len>;
fn len(&self) -> Self::Len;
fn get_edge(
&self,
len: <ribbit::Packed<Self::Edge> as edge::Meta>::Len,
) -> ribbit::Packed<Self::Edge>;
fn get_byte(&self, index: <ribbit::Packed<Self::Edge> as edge::Meta>::Len) -> Option<u8>;
#[inline]
unsafe fn get_byte_unchecked(
&self,
index: <ribbit::Packed<Self::Edge> as edge::Meta>::Len,
) -> u8 {
match self.get_byte(index) {
Some(byte) => byte,
None => if_validate!(unreachable!(), unsafe {
core::hint::unreachable_unchecked()
}),
}
}
#[inline]
fn match_exact(
&self,
meta: <Self::Edge as ribbit::Pack>::Packed,
) -> Option<<ribbit::Packed<Self::Edge> as edge::Meta>::Len> {
let len = self.match_prefix(meta);
(len >= meta.len().into()).then_some(meta.len())
}
fn match_prefix(&self, meta: <Self::Edge as ribbit::Pack>::Packed) -> Self::Len;
fn prefix(self, end: Self::Len) -> Self;
fn suffix(self, start: Self::Len) -> Self;
fn common_prefix(self, other: Self) -> Self;
}
pub(crate) trait Write<R: Read>: fmt::Debug + Default {
type Len: Copy + fmt::Debug;
fn new(prefix: R, key: ribbit::Packed<R::Edge>) -> (Self, Self::Len);
fn replace(&mut self, start: Self::Len, node: u8, edge: ribbit::Packed<R::Edge>) -> Self::Len;
}