#![doc = include_str!("../README.md")]
#![cfg_attr(feature = "rustc", feature(rustc_private))]
#![cfg_attr(feature = "simd", feature(portable_simd, unchecked_math))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs)]
use self::pointer::PointerFamily;
use index_vec::Idx;
use std::hash::Hash;
pub mod bitset;
mod domain;
pub mod map;
mod matrix;
pub mod pointer;
mod set;
#[cfg(test)]
mod test_utils;
#[doc(hidden)]
pub use index_vec as _index_vec;
pub use domain::IndexedDomain;
pub use matrix::IndexMatrix;
pub use set::IndexSet;
pub struct MarkerOwned;
pub struct MarkerRef;
pub struct MarkerIndex;
pub trait ToIndex<T: IndexedValue, M> {
fn to_index(self, domain: &IndexedDomain<T>) -> T::Index;
}
impl<T: IndexedValue> ToIndex<T, MarkerOwned> for T {
fn to_index(self, domain: &IndexedDomain<T>) -> T::Index {
domain.index(&self)
}
}
impl<'a, T: IndexedValue> ToIndex<T, MarkerRef> for &'a T {
#[inline]
fn to_index(self, domain: &IndexedDomain<T>) -> T::Index {
domain.index(self)
}
}
impl<T: IndexedValue> ToIndex<T, MarkerIndex> for T::Index {
#[inline]
fn to_index(self, _domain: &IndexedDomain<T>) -> T::Index {
self
}
}
pub trait IndexedValue: Clone + PartialEq + Eq + Hash {
type Index: Idx;
}
#[macro_export]
macro_rules! define_index_type {
(
$(#[$attrs:meta])*
$v:vis struct $type:ident for $target:ident $(<$($l:lifetime),*>)? = $raw:ident;
$($CONFIG_NAME:ident = $value:expr;)* $(;)?
) => {
$crate::_index_vec::define_index_type! {
$(#[$attrs])*
$v struct $type = $raw;
$($CONFIG_NAME = $value;)*
}
impl $(<$($l),*>)? $crate::IndexedValue for $target $(<$($l),*>)? {
type Index = $type;
}
}
}
pub trait Captures<'a> {}
impl<'a, T: ?Sized> Captures<'a> for T {}
pub trait FromIndexicalIterator<'a, T: IndexedValue + 'a, P: PointerFamily<'a>, M, A>:
Sized
{
fn from_indexical_iter(
iter: impl Iterator<Item = A>,
domain: &P::Pointer<IndexedDomain<T>>,
) -> Self;
}
pub trait IndexicalIteratorExt<'a, T: IndexedValue + 'a, P: PointerFamily<'a>, M>:
Iterator + Sized
{
fn collect_indexical<B>(self, domain: &P::Pointer<IndexedDomain<T>>) -> B
where
B: FromIndexicalIterator<'a, T, P, M, Self::Item>,
{
FromIndexicalIterator::from_indexical_iter(self, domain)
}
}
impl<'a, I: Iterator, T: IndexedValue + 'a, P: PointerFamily<'a>, M>
IndexicalIteratorExt<'a, T, P, M> for I
{
}