traiter/collections/
traits.rs1pub trait Capacitary {
2 type Capacity;
3
4 #[cfg_attr(
6 feature = "std",
7 doc = r##"
8```
9use traiter::collections::Capacitary;
10let collection = Vec::<i8>::with_capacity(10);
11assert_eq!(Capacitary::capacity(&collection), 10);
12```
13"##
14 )]
15 fn capacity(self) -> Self::Capacity;
16}
17
18pub trait Clearable {
19 #[cfg_attr(
21 feature = "std",
22 doc = r##"
23```
24use traiter::collections::{Clearable, Emptiable};
25let mut collection = vec![0];
26assert!(!Emptiable::is_empty(&collection));
27Clearable::clear(&mut collection);
28assert!(Emptiable::is_empty(&collection));
29```
30"##
31 )]
32 fn clear(self);
33}
34
35pub trait Emptiable {
36 fn is_empty(self) -> bool;
43}
44
45pub trait ItemInsertable {
46 type Key;
47 type Output;
48 type Value;
49
50 #[cfg_attr(
52 feature = "std",
53 doc = r##"
54```
55use traiter::collections::ItemInsertable;
56assert_eq!(ItemInsertable::insert_item(&mut vec![10], 0, 20), ());
57```
58"##
59 )]
60 fn insert_item(self, key: Self::Key, value: Self::Value) -> Self::Output;
61}
62
63pub trait ItemRemovable {
64 type Key;
65 type Output;
66
67 #[cfg_attr(
69 feature = "std",
70 doc = r##"
71```
72use traiter::collections::ItemRemovable;
73assert_eq!(ItemRemovable::remove_item(&mut vec![10], 0), 10);
74```
75"##
76 )]
77 fn remove_item(self, key: Self::Key) -> Self::Output;
78}
79
80pub trait Iterable {
81 type Item;
82 type Output: Iterator<Item = Self::Item>;
83
84 fn iter(self) -> Self::Output;
90}
91
92pub trait KeyContainer {
93 type Key;
94
95 #[cfg_attr(
97 feature = "std",
98 doc = r##"
99```
100use std::collections::HashMap;
101use traiter::collections::{KeyContainer, ItemInsertable};
102let mut collection = HashMap::new();
103assert!(!KeyContainer::contains_key(&collection, &10));
104assert_eq!(ItemInsertable::insert_item(&mut collection, 10, 20), None);
105assert!(KeyContainer::contains_key(&collection, &10));
106```
107"##
108 )]
109 fn contains_key(self, key: Self::Key) -> bool;
110}
111
112pub trait Lengthsome {
113 type Length;
114
115 fn len(self) -> Self::Length;
122}
123
124pub trait MutablyIterable {
125 type Item;
126 type Output: Iterator<Item = Self::Item>;
127
128 fn iter_mut(self) -> Self::Output;
134}
135
136pub trait Reservable: Capacitary {
137 #[cfg_attr(
139 feature = "std",
140 doc = r##"
141```
142use traiter::collections::{Capacitary, Reservable};
143let mut collection = Vec::<i8>::with_capacity(10);
144assert_eq!(Capacitary::capacity(&collection), 10);
145Reservable::reserve(&mut collection, 20);
146assert_eq!(Capacitary::capacity(&collection), 20);
147```
148"##
149 )]
150 fn reserve(self, additional: Self::Capacity);
151}
152
153pub trait TryReservable: Capacitary {
154 type Error;
155
156 #[cfg_attr(
158 feature = "std",
159 doc = r##"
160```
161use traiter::collections::{Capacitary, Reservable};
162let mut collection = Vec::<i8>::with_capacity(10);
163assert_eq!(Capacitary::capacity(&collection), 10);
164Reservable::reserve(&mut collection, 20);
165assert_eq!(Capacitary::capacity(&collection), 20);
166```
167"##
168 )]
169 fn try_reserve(
170 self,
171 additional: Self::Capacity,
172 ) -> Result<(), Self::Error>;
173}
174
175pub trait ValueContainer {
176 type Value;
177
178 fn contains_value(self, value: Self::Value) -> bool;
185}
186
187pub trait ValueInsertable {
188 type Output;
189 type Value;
190
191 #[cfg_attr(
193 feature = "std",
194 doc = r##"
195```
196use std::collections::HashSet;
197use traiter::collections::{ValueContainer, ValueInsertable};
198let mut collection = HashSet::new();
199assert!(!ValueContainer::contains_value(&collection, &10));
200assert!(ValueInsertable::insert_value(&mut collection, 10));
201assert!(ValueContainer::contains_value(&collection, &10));
202```
203"##
204 )]
205 fn insert_value(self, value: Self::Value) -> Self::Output;
206}
207
208pub trait ValueRemovable {
209 type Output;
210 type Value;
211
212 #[cfg_attr(
214 feature = "std",
215 doc = r##"
216```
217use std::collections::HashSet;
218use traiter::collections::ValueRemovable;
219let mut collection = HashSet::new();
220collection.insert(10);
221assert!(ValueRemovable::remove_value(&mut collection, &10));
222assert!(!ValueRemovable::remove_value(&mut collection, &10));
223```
224"##
225 )]
226 fn remove_value(self, value: Self::Value) -> Self::Output;
227}