use crate::LeafRef;
#[cfg(doc)]
use crate::{LeafNext, SkipList};
use core::convert::Infallible;
use core::fmt;
use core::marker::PhantomData;
use core::ops::{AddAssign, SubAssign};
use integral_constant::{Bool, Usize};
mod detail {
use integral_constant::Constant;
pub trait StoreKeysPriv {
type Key<T: Clone>: Clone;
fn as_key<T: Clone>(_value: &T) -> Option<Self::Key<T>> {
None
}
fn to_leaf<T: Clone>(_key: Option<Self::Key<T>>) -> Option<T> {
None
}
}
pub trait FanoutPriv: Constant<usize> {}
}
pub(crate) use detail::*;
pub trait StoreKeys: StoreKeysPriv {}
impl StoreKeys for Bool<false> {}
impl StoreKeysPriv for Bool<false> {
type Key<T: Clone> = Infallible;
}
impl StoreKeys for Bool<true> {}
impl StoreKeysPriv for Bool<true> {
type Key<T: Clone> = T;
fn as_key<T: Clone>(value: &T) -> Option<T> {
Some(value.clone())
}
fn to_leaf<T: Clone>(key: Option<T>) -> Option<T> {
key
}
}
pub trait Fanout: FanoutPriv {}
impl<const N: usize> Fanout for Usize<N> {}
impl<const N: usize> FanoutPriv for Usize<N> {}
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
pub struct NoSize;
impl fmt::Debug for NoSize {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "∅")
}
}
impl AddAssign for NoSize {
fn add_assign(&mut self, _rhs: Self) {}
}
impl SubAssign for NoSize {
fn sub_assign(&mut self, _rhs: Self) {}
}
mod sealed {
pub trait Sealed {}
}
pub trait ListOptions: sealed::Sealed {
type SizeType: Clone + Default + Eq + AddAssign + SubAssign;
type StoreKeys: StoreKeys;
type Fanout: Fanout;
type Align;
}
pub type LeafSize<L> = <<L as LeafRef>::Options as ListOptions>::SizeType;
#[rustfmt::skip]
pub type Options<
SizeType = NoSize,
const STORE_KEYS: bool = false,
const FANOUT: usize = 8,
Align = (),
> = TypedOptions<
SizeType,
Bool<STORE_KEYS>,
Usize<FANOUT>,
Align,
>;
#[allow(clippy::type_complexity)]
#[rustfmt::skip]
pub struct TypedOptions<
SizeType = NoSize,
StoreKeys = Bool<false>,
Fanout = Usize<8>,
Align = (),
>(PhantomData<fn() -> (
SizeType,
StoreKeys,
Fanout,
Align,
)>);
#[rustfmt::skip]
impl<
SizeType,
StoreKeys,
Fanout,
Align,
> sealed::Sealed for TypedOptions<
SizeType,
StoreKeys,
Fanout,
Align,
> {}
#[rustfmt::skip]
impl<
SizeType: Clone + Default + Eq + AddAssign + SubAssign,
StoreKeys: self::StoreKeys,
Fanout: self::Fanout,
Align,
> ListOptions for TypedOptions<
SizeType,
StoreKeys,
Fanout,
Align,
> {
type SizeType = SizeType;
type StoreKeys = StoreKeys;
type Fanout = Fanout;
type Align = Align;
}