1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use crate::*;
use std::ops::{Index, IndexMut};
/// Collection with mutable capacity.
pub trait CapacityMut = Capacity + Reserve;
/// 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<T> = Collection<Item = T> + Len + Back;
/// Mutable stack data structure.
///
/// This trait alias describes the mutables operations on a stack.
/// See [`Stack`] for more details.
pub trait StackMut<T> = Stack<T> + BackMut + PushBack + PopBack;
/// Immutable array data structure (conventionally nammed "Vec").
///
/// A Vec is essentially a [`Stack`] indexable by a `usize`.
pub trait Vec<T> = Stack<T> + Index<usize, Output = T>;
/// Mutable Vec data structure.
///
/// This trait alias describes the mutables operations on a Vec.
/// See [`Vec`] for more details.
pub trait VecMut<T> = Vec<T> + StackMut<T> + IndexMut<usize>;
/// 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<T> = Stack<T> + Front;
/// Mutable double-ended queue.
///
/// This trait alias describes the mutables operations on a deque.
/// See [`Deque`] for more details.
pub trait DequeMut<T> = StackMut<T> + FrontMut + PushFront + PopFront;
/// Immutable indexable deque.
///
/// See [`Deque`] and [`Vec`] for more details.
pub trait VecDeque<T> = Deque<T> + Vec<T>;
/// Mutable indexable deque.
///
/// See [`VecDeque`], [`DequeMut`] and [`VecMut`] for more details.
pub trait VecDequeMut<T> = VecDeque<T> + DequeMut<T> + VecMut<T>;
/// Imutable set data structure.
///
/// A set is an unordered collection storing at most one single copy of each element.
pub trait Set<T> = Collection<Item = T> + Len + for<'a> Get<&'a T>;
/// Mutable set data structure.
pub trait SetMut<T> = Set<T> + Insert<Output = bool> + for<'a> Remove<&'a T>;
/// Imutable map data structure.
///
/// A map is an unordered collection storing key-value pairs, indexed by the key.
pub trait Map<K, V> =
Keyed<Key = K, Item = V> + Len + for<'a> Get<&'a K> + for<'a> GetKeyValue<&'a K>;
/// Mutable map data structure.
pub trait MapMut<K, V> =
Map<K, V> + for<'a> GetMut<&'a K> + MapInsert<K, Output = Option<V>> + for<'a> Remove<&'a K>;
/// 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<T> = Collection<Item = T> + Len + Get<usize>;
/// Mutable slab data structure.
pub trait SlabMut<T> = Slab<T> + GetMut<usize> + Insert<Output = usize> + Remove<usize>;