use crate::*; use core::ops::{Index, IndexMut}; /// Collection with mutable capacity. pub trait CapacityMut: Capacity + Reserve {} impl CapacityMut for C {} /// Immutable stack data structure. /// /// A stack provides two main operations: /// - [`PushBack::push_back`], which adds an element to the collection, and /// - [`PopBack::pop_back`], which removes the most recently added element that was not yet removed. /// /// This trait alias describes the immutables operations derived from the two main operation above: /// - [`Len::len`], returning the number of elements in the stack, and /// - [`Back::back`], returning a reference to the most recently added element that was not yet removed. pub trait Stack: Collection + Len + Back {} impl + Len + Back> Stack for C {} /// Mutable stack data structure. /// /// This trait alias describes the mutables operations on a stack. /// See [`Stack`] for more details. pub trait StackMut: Stack + BackMut + PushBack + PopBack {} impl + BackMut + PushBack + PopBack> StackMut for C {} /// Immutable array data structure (conventionally nammed "Vec"). /// /// A Vec is essentially a [`Stack`] indexable by a `usize`. pub trait Vec: Stack + Index {} impl + Index> Vec for C {} /// Mutable Vec data structure. /// /// This trait alias describes the mutables operations on a Vec. /// See [`Vec`] for more details. pub trait VecMut: Vec + StackMut + IndexMut {} impl + StackMut + IndexMut> VecMut for C {} /// Immutable double-ended queue. /// /// A double-ended queue (abbreviated to deque) is a generalization of a stack in which /// elements can be added and removed from both ends. /// Such a data structure provides two additional operations compared to regular stacks: /// - [`PushFront::push_front`], which adds an element to the front of collection, and /// - [`PopFront::pop_front`], which removes the front element of the collection. /// /// This trait alias describes the immutables operations available on deques. pub trait Deque: Stack + Front {} impl + Front> Deque for C {} /// Mutable double-ended queue. /// /// This trait alias describes the mutables operations on a deque. /// See [`Deque`] for more details. pub trait DequeMut: StackMut + FrontMut + PushFront + PopFront {} impl + FrontMut + PushFront + PopFront> DequeMut for C {} /// Immutable indexable deque. /// /// See [`Deque`] and [`Vec`] for more details. pub trait VecDeque: Deque + Vec {} impl + Vec> VecDeque for C {} /// Mutable indexable deque. /// /// See [`VecDeque`], [`DequeMut`] and [`VecMut`] for more details. pub trait VecDequeMut: VecDeque + DequeMut + VecMut {} impl + DequeMut + VecMut> VecDequeMut for C {} /// Imutable set data structure. /// /// A set is an unordered collection storing at most one single copy of each element. pub trait Set: Collection + Len + for<'a> Get<&'a T> {} impl + Len + for<'a> Get<&'a T>> Set for C {} /// Mutable set data structure. pub trait SetMut: Set + Insert + for<'a> Remove<&'a T> {} impl + Insert + for<'a> Remove<&'a T>> SetMut for C {} /// Imutable map data structure. /// /// A map is an unordered collection storing key-value pairs, indexed by the key. pub trait Map: Keyed + Len + for<'a> Get<&'a K> + for<'a> GetKeyValue<&'a K> { } impl + Len + for<'a> Get<&'a K> + for<'a> GetKeyValue<&'a K>> Map for C { } /// Mutable map data structure. pub trait MapMut: Map + for<'a> GetMut<&'a K> + MapInsert> + for<'a> Remove<&'a K> { } impl< K, V, C: Map + for<'a> GetMut<&'a K> + MapInsert> + for<'a> Remove<&'a K>, > MapMut for C { } /// Imutable slab data structure. /// /// A slab is a linear collection storing each element at a given index. /// The index of the element is allocated and returned upon insertion. pub trait Slab: Collection + Len + Get {} impl + Len + Get> Slab for C {} /// Mutable slab data structure. pub trait SlabMut: Slab + GetMut + Insert + Remove {} impl + GetMut + Insert + Remove> SlabMut for C {}