Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! This crate provide traits to describe common operations available on data structures.
2 //! This is particularly useful when building new types on top of generic data structures without relying on the actual implementation of the underlying data structure.
3 //!
4 //! Here is an example of the kind of traits provided by this crate:
5 //! ```rust
6 //! # use cc_traits::Collection;
7 //! /// Mutable collection where new elements can be inserted.
8 //! pub trait Insert: Collection {
9 //! /// The output of the insertion function.
10 //! type Output;
11 //!
12 //! /// Insert a new element in the collection.
13 //! fn insert(&mut self, element: Self::Item) -> Self::Output;
14 //! }
15 //! ```
16 //!
17 //! # Usage
18 //!
19 //! Such traits can be used to define collections with special properties,
20 //! independently of the actual internal data structure.
21 //! For instance the following code defines an `Ordered<S>` stack collection,
22 //! guarantying the well-sortedness of the elements in the stack.
23 //!
24 //! ```rust
25 //! use cc_traits::{
26 //! Collection,
27 //! Back,
28 //! PushBack
29 //! };
30 //!
31 //! /// Ordered stack.
32 //! pub struct Ordered<S> {
33 //! inner: S
34 //! }
35 //!
36 //! impl<S> Ordered<S> {
37 //! pub fn new() -> Self where S: Default {
38 //! Ordered {
39 //! inner: S::default()
40 //! }
41 //! }
42 //! }
43 //!
44 //! impl<S> Ordered<S> {
45 //! /// Push the given element on the stack iff it is grater or equal
46 //! /// to every other element already in the stack.
47 //! pub fn try_push<T>(&mut self, element: T) -> Result<(), T>
48 //! where
49 //! T: PartialOrd,
50 //! S: Collection<Item=T> + Back + PushBack, // `S` must be a stack providing `back` and `push_back`.
51 //! for<'a> S::ItemRef<'a>: PartialOrd<&'a T> // The reference type must be comparable with other reference types.
52 //! {
53 //! if self.inner.back().map(|back| back <= &element).unwrap_or(true) {
54 //! self.inner.push_back(element);
55 //! Ok(())
56 //! } else {
57 //! Err(element)
58 //! }
59 //! }
60 //! }
61 //!
62 //! #[cfg(feature = "std")]
63 //! fn ordered_stack_usage<S>()
64 //! where
65 //! S: Default + Collection<Item = i32> + Back + PushBack,
66 //! for<'a> S::ItemRef<'a>: PartialOrd<&'a i32>,
67 //! {
68 //! let mut ordered: Ordered<S> = Ordered::new();
69 //! assert!(ordered.try_push(1).is_ok());
70 //! assert!(ordered.try_push(2).is_ok());
71 //! assert!(ordered.try_push(0).is_err());
72 //! }
73 //!
74 //! #[cfg(feature = "std")]
75 //! ordered_stack_usage::<Vec<i32>>(); // a `Vec` is a stack so it works.
76 //!
77 //! #[cfg(feature = "std")]
78 //! use std::collections::VecDeque;
79 //! #[cfg(feature = "std")]
80 //! ordered_stack_usage::<VecDeque<i32>>(); // a `VecDeque` is also a stack.
81 //! ```
82 //!
83 //! # Trait aliases
84 //!
85 //! By enabling the `nightly` you can get access to
86 //! some trait alias definitions that can be useful to reduce the
87 //! verbosity of your code.
88 //! Here is an example of such aliases defining the common interface of stacks:
89 //! ```ignore
90 //! pub trait Stack<T> = Collection<Item=T> + Len + Back;
91 //! pub trait StackMut<T> = Stack<T> + BackMut + PushBack + PopBack;
92 //! ```
93 //!
94 //! As of version 0.8.0, those traits are also available without the `nightly`
95 //! feature as regular trait definitions.
96 //!
97 //! # Standard library
98 //!
99 //! By default, all the traits defined in this crate are implemented (when relevant)
100 //! for the standard library collections.
101 //! You can disable it by using the `nostd` feature.
102 //!
103 //! # Foreign implementations
104 //!
105 //! In addition to the standard library,
106 //! traits are implemented for
107 //! some popular crates if you enable the feature of the same name.
108 //! Here are the supported crates:
109 //!
110 //! - [`slab`](https://crates.io/crates/slab) providing the `Slab` collection.
111 //! - [`smallvec`](https://crates.io/crates/smallvec) providing the `SmallVec` collection.
112 //! - [`serde_json`](https://crates.io/crates/serde_json) providing the `Map<String, Value>` collection for JSON objects.
113 //! - [`ijson`](https://crates.io/crates/ijson) providing the `IObject` and `IArray` collections.
114 #![cfg_attr(not(feature = "std"), no_std)]
115 #![cfg_attr(feature = "nightly", feature(trait_alias))]
116
117 #[cfg(feature = "alloc")]
118 extern crate allocrust-analyzer cargo cc-traits 2.0.0 alloc/;
119 extern crate corerust-analyzer cargo cc-traits 2.0.0 core/;
120
121 mod implsrust-analyzer cargo cc-traits 2.0.0 impls/;
122 mod macrosrust-analyzer cargo cc-traits 2.0.0 macros/;
123
124 #[cfg(feature = "nightly")]
125 mod alias;
126 #[cfg(feature = "nightly")]
127 pub use alias::*;
128
129 #[cfg(not(feature = "nightly"))]
130 mod non_aliasrust-analyzer cargo cc-traits 2.0.0 non_alias/;
131 #[cfg(not(feature = "nightly"))]
132 pub use non_aliasrust-analyzer cargo cc-traits 2.0.0 non_alias/::*;
133
134 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#};
135
136 /// Abstract collection.
137 pub trait Collectionrust-analyzer cargo cc-traits 2.0.0 Collection# {
138 /// Type of the items of the collection.
139 type Itemrust-analyzer cargo cc-traits 2.0.0 Collection#Item#;
140 }
141
142 /// Abstract collection that can be immutably referenced.
143 pub trait CollectionRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#: Collectionrust-analyzer cargo cc-traits 2.0.0 Collection# {
144 /// Type of references to items of the collection.
145 type ItemRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#ItemRef#<'a>: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#<Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# = Self::Itemrust-analyzer cargo cc-traits 2.0.0 Collection#Item#>
146 where
147 Self: 'a;
148
149 /// Changes an item reference into a shorter lived reference.
150 ///
151 /// Item references are [covariant](https://doc.rust-lang.org/nomicon/subtyping.html#variance) with
152 /// regard to the defined lifetime parameter `'a`.
153 /// Since this cannot be directly expressed by the type system, this associated function
154 /// allows one to explicitly shorten the reference's lifetime.
155 ///
156 /// You can use the [`covariant_item_ref!`] macro to automatically
157 /// implement this function.
158 fn upcast_item_refrust-analyzer cargo cc-traits 2.0.0 CollectionRef#upcast_item_ref().<'short, 'long: 'short>(r: Self::ItemRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#ItemRef#<'long>) -> Self::ItemRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#ItemRef#<'short>
159 where
160 Self: 'long;
161 }
162
163 /// Collection where each item reference can be converted into a standard
164 /// "simple" rust reference.
165 ///
166 /// This trait is particularly useful to avoid having to include where bounds
167 /// of the form `for<'r> T::ItemRef<'r>: Into<&'r T::Item>`, which can
168 /// currently lead the compiler to try to prove `T: 'static`
169 /// (see https://github.com/rust-lang/rust/pull/96709#issuecomment-1182403490)
170 /// for more details.
171 pub trait SimpleCollectionRefrust-analyzer cargo cc-traits 2.0.0 SimpleCollectionRef#: CollectionRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef# {
172 fn into_refrust-analyzer cargo cc-traits 2.0.0 SimpleCollectionRef#into_ref().<'r>(r: Self::ItemRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#ItemRef#<'r>) -> &'r Self::Itemrust-analyzer cargo cc-traits 2.0.0 Collection#Item#
173 where
174 Self: 'r;
175 }
176
177 /// Abstract collection that can be mutably referenced.
178 pub trait CollectionMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#: Collectionrust-analyzer cargo cc-traits 2.0.0 Collection# {
179 /// Type of mutable references to items of the collection.
180 type ItemMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#ItemMut#<'a>: DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#<Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# = Self::Itemrust-analyzer cargo cc-traits 2.0.0 Collection#Item#>
181 where
182 Self: 'a;
183
184 /// Changes an item mutable reference into a shorter lived mutable reference.
185 ///
186 /// See the [`CollectionRef::upcast_item_ref`] function for more information.
187 /// You can use the [`covariant_item_mut!`] macro to automatically
188 /// implement this function.
189 fn upcast_item_mutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#upcast_item_mut().<'short, 'long: 'short>(r: Self::ItemMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#ItemMut#<'long>) -> Self::ItemMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#ItemMut#<'short>
190 where
191 Self: 'long;
192 }
193
194 /// Collection where each item reference can be converted into a standard
195 /// "simple" rust reference.
196 ///
197 /// This trait is particularly useful to avoid having to include where bounds
198 /// of the form `for<'r> T::ItemMut<'r>: Into<&'r mut T::Item>`, which can
199 /// currently lead the compiler to try to prove `T: 'static`
200 /// (see https://github.com/rust-lang/rust/pull/96709#issuecomment-1182403490)
201 /// for more details.
202 pub trait SimpleCollectionMutrust-analyzer cargo cc-traits 2.0.0 SimpleCollectionMut#: CollectionMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut# {
203 fn into_mutrust-analyzer cargo cc-traits 2.0.0 SimpleCollectionMut#into_mut().<'r>(r: Self::ItemMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#ItemMut#<'r>) -> &'r mut Self::Itemrust-analyzer cargo cc-traits 2.0.0 Collection#Item#
204 where
205 Self: 'r;
206 }
207
208 /// Abstract keyed collection.
209 pub trait Keyedrust-analyzer cargo cc-traits 2.0.0 Keyed#: Collectionrust-analyzer cargo cc-traits 2.0.0 Collection# {
210 /// Type of the keys indexing each item of the collection.
211 type Keyrust-analyzer cargo cc-traits 2.0.0 Keyed#Key#;
212 }
213
214 /// Abstract keyed collection whose key can be referenced.
215 pub trait KeyedRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef#: Keyedrust-analyzer cargo cc-traits 2.0.0 Keyed# {
216 /// Type of references to keys of the collection.
217 type KeyRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef#KeyRef#<'a>: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# + Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#<Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# = Self::Keyrust-analyzer cargo cc-traits 2.0.0 Keyed#Key#>
218 where
219 Self: 'a;
220
221 /// Changes a key reference into a shorter lived reference.
222 ///
223 /// See the [`CollectionRef::upcast_item_ref`] function for more information.
224 /// You can use the [`covariant_key_ref!`] macro to automatically
225 /// implement this function.
226 fn upcast_key_refrust-analyzer cargo cc-traits 2.0.0 KeyedRef#upcast_key_ref().<'short, 'long: 'short>(r: Self::KeyRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef#KeyRef#<'long>) -> Self::KeyRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef#KeyRef#<'short>
227 where
228 Self: 'long;
229 }
230
231 /// Keyed collection where each key reference can be converted into a standard
232 /// "simple" rust reference.
233 ///
234 /// This trait is particularly useful to avoid having to include where bounds
235 /// of the form `for<'r> T::KeyRef<'r>: Into<&'r T::Key>`, which can
236 /// currently lead the compiler to try to prove `T: 'static`
237 /// (see https://github.com/rust-lang/rust/pull/96709#issuecomment-1182403490)
238 /// for more details.
239 pub trait SimpleKeyedRefrust-analyzer cargo cc-traits 2.0.0 SimpleKeyedRef#: KeyedRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef# {
240 fn into_refrust-analyzer cargo cc-traits 2.0.0 SimpleKeyedRef#into_ref().<'r>(r: Self::KeyRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef#KeyRef#<'r>) -> &'r Self::Keyrust-analyzer cargo cc-traits 2.0.0 Keyed#Key#
241 where
242 Self: 'r;
243 }
244
245 /// Collection that can be created with a minimum given capacity.
246 pub trait WithCapacityrust-analyzer cargo cc-traits 2.0.0 WithCapacity# {
247 /// Creates a new instance of `Self` with the given minimum capacity.
248 fn with_capacityrust-analyzer cargo cc-traits 2.0.0 WithCapacity#with_capacity().(capacity: usize) -> Self;
249 }
250
251 /// Sized collection.
252 pub trait Lenrust-analyzer cargo cc-traits 2.0.0 Len# {
253 /// Returns the number of elements in the collection.
254 fn lenrust-analyzer cargo cc-traits 2.0.0 Len#len().(&self) -> usize;
255
256 /// Checks if the collection is empty.
257 fn is_emptyrust-analyzer cargo cc-traits 2.0.0 Len#is_empty().(&self) -> bool {
258 self.lenrust-analyzer cargo cc-traits 2.0.0 Len#len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0
259 }
260 }
261
262 /// Collection with known capacity.
263 pub trait Capacityrust-analyzer cargo cc-traits 2.0.0 Capacity# {
264 /// Returns the current capacity of the collection.
265 ///
266 /// This corresponds to the number of elements the collection can hold without reallocation.
267 fn capacityrust-analyzer cargo cc-traits 2.0.0 Capacity#capacity().(&self) -> usize;
268 }
269
270 /// Collection that can extend their capacity.
271 pub trait Reserverust-analyzer cargo cc-traits 2.0.0 Reserve# {
272 /// Reserve enough memory for `edditional` more elements.
273 fn reserverust-analyzer cargo cc-traits 2.0.0 Reserve#reserve().(&mut self, additional: usize);
274 }
275
276 /// Queryable collection.
277 pub trait Getrust-analyzer cargo cc-traits 2.0.0 Get#<T>: CollectionRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef# {
278 /// Returns a reference to the item stored behind the given key (if any).
279 fn getrust-analyzer cargo cc-traits 2.0.0 Get#get().(&self, key: T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self::ItemRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#ItemRef#<'_>>;
280
281 /// Checks if the collection contains an item behind the given key.
282 fn containsrust-analyzer cargo cc-traits 2.0.0 Get#contains().(&self, key: T) -> bool {
283 self.getrust-analyzer cargo cc-traits 2.0.0 Get#get().(key).is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().()
284 }
285 }
286
287 /// Mutably queryable collection.
288 pub trait GetMutrust-analyzer cargo cc-traits 2.0.0 GetMut#<T>: Getrust-analyzer cargo cc-traits 2.0.0 Get#<T> + CollectionMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut# {
289 /// Returns a mutable reference to the item stored behind the given key (if any).
290 fn get_mutrust-analyzer cargo cc-traits 2.0.0 GetMut#get_mut().(&mut self, key: T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self::ItemMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#ItemMut#<'_>>;
291 }
292
293 /// Queryable map.
294 pub trait GetKeyValuerust-analyzer cargo cc-traits 2.0.0 GetKeyValue#<T>: CollectionRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef# + KeyedRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef# {
295 /// Returns the key-value pair matching the given `key`.
296 fn get_key_valuerust-analyzer cargo cc-traits 2.0.0 GetKeyValue#get_key_value().(&self, key: T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(Self::KeyRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef#KeyRef#<'_>, Self::ItemRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#ItemRef#<'_>)>;
297 }
298
299 /// Mutably queryable map.
300 pub trait GetKeyValueMutrust-analyzer cargo cc-traits 2.0.0 GetKeyValueMut#<T>: CollectionMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut# + KeyedRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef# {
301 /// Returns the key-value pair matching the given `key`, with a mutable reference to the value.
302 fn get_key_value_mutrust-analyzer cargo cc-traits 2.0.0 GetKeyValueMut#get_key_value_mut().(&mut self, key: T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(Self::KeyRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef#KeyRef#<'_>, Self::ItemMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#ItemMut#<'_>)>;
303 }
304
305 /// Collection exposing a reference to its front element.
306 pub trait Frontrust-analyzer cargo cc-traits 2.0.0 Front#: CollectionRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef# {
307 /// Get a reference to the front element of the collection.
308 fn frontrust-analyzer cargo cc-traits 2.0.0 Front#front().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self::ItemRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#ItemRef#<'_>>;
309 }
310
311 impl<T: Getrust-analyzer cargo cc-traits 2.0.0 Get#<usize> + Lenrust-analyzer cargo cc-traits 2.0.0 Len#> Frontrust-analyzer cargo cc-traits 2.0.0 Front# for T {
312 fn frontrust-analyzer cargo cc-traits 2.0.0 impl#[T][Front]front().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo cc-traits 2.0.0 impl#[T][Front]::ItemRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#ItemRef#<'_>> {
313 match self.lenrust-analyzer cargo cc-traits 2.0.0 Len#len().() {
314 0 => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
315 _ => self.getrust-analyzer cargo cc-traits 2.0.0 Get#get().(0),
316 }
317 }
318 }
319
320 /// Collection exposing a reference to its back element.
321 pub trait Backrust-analyzer cargo cc-traits 2.0.0 Back#: CollectionRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef# {
322 /// Get a reference to the back element of the collection.
323 fn backrust-analyzer cargo cc-traits 2.0.0 Back#back().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self::ItemRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#ItemRef#<'_>>;
324 }
325
326 impl<T: Getrust-analyzer cargo cc-traits 2.0.0 Get#<usize> + Lenrust-analyzer cargo cc-traits 2.0.0 Len#> Backrust-analyzer cargo cc-traits 2.0.0 Back# for T {
327 fn backrust-analyzer cargo cc-traits 2.0.0 impl#[T][Back]back().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo cc-traits 2.0.0 impl#[T][Back]::ItemRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#ItemRef#<'_>> {
328 match self.lenrust-analyzer cargo cc-traits 2.0.0 Len#len().() {
329 0 => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
330 l => self.getrust-analyzer cargo cc-traits 2.0.0 Get#get().(l rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1),
331 }
332 }
333 }
334
335 /// Collection exposing a mutable reference to its front element.
336 pub trait FrontMutrust-analyzer cargo cc-traits 2.0.0 FrontMut#: CollectionMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut# {
337 /// Get a mutable reference to the front element of the collection.
338 fn front_mutrust-analyzer cargo cc-traits 2.0.0 FrontMut#front_mut().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self::ItemMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#ItemMut#<'_>>;
339 }
340
341 impl<T: GetMutrust-analyzer cargo cc-traits 2.0.0 GetMut#<usize> + Lenrust-analyzer cargo cc-traits 2.0.0 Len#> FrontMutrust-analyzer cargo cc-traits 2.0.0 FrontMut# for T {
342 fn front_mutrust-analyzer cargo cc-traits 2.0.0 impl#[T][FrontMut]front_mut().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo cc-traits 2.0.0 impl#[T][FrontMut]::ItemMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#ItemMut#<'_>> {
343 match self.lenrust-analyzer cargo cc-traits 2.0.0 Len#len().() {
344 0 => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
345 _ => self.get_mutrust-analyzer cargo cc-traits 2.0.0 GetMut#get_mut().(0),
346 }
347 }
348 }
349
350 /// Collection exposing a mutable reference to its back element.
351 pub trait BackMutrust-analyzer cargo cc-traits 2.0.0 BackMut#: CollectionMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut# {
352 /// Get a mutable reference to the back element of the collection.
353 fn back_mutrust-analyzer cargo cc-traits 2.0.0 BackMut#back_mut().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self::ItemMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#ItemMut#<'_>>;
354 }
355
356 impl<T: GetMutrust-analyzer cargo cc-traits 2.0.0 GetMut#<usize> + Lenrust-analyzer cargo cc-traits 2.0.0 Len#> BackMutrust-analyzer cargo cc-traits 2.0.0 BackMut# for T {
357 fn back_mutrust-analyzer cargo cc-traits 2.0.0 impl#[T][BackMut]back_mut().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo cc-traits 2.0.0 impl#[T][BackMut]::ItemMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#ItemMut#<'_>> {
358 match self.lenrust-analyzer cargo cc-traits 2.0.0 Len#len().() {
359 0 => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
360 l => self.get_mutrust-analyzer cargo cc-traits 2.0.0 GetMut#get_mut().(l rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1),
361 }
362 }
363 }
364
365 /// Mutable collection where new elements can be inserted.
366 pub trait Insertrust-analyzer cargo cc-traits 2.0.0 Insert#: Collectionrust-analyzer cargo cc-traits 2.0.0 Collection# {
367 /// The output of the insertion function.
368 type Outputrust-analyzer cargo cc-traits 2.0.0 Insert#Output#;
369
370 /// Insert a new element in the collection.
371 fn insertrust-analyzer cargo cc-traits 2.0.0 Insert#insert().(&mut self, element: Self::Itemrust-analyzer cargo cc-traits 2.0.0 Collection#Item#) -> Self::Outputrust-analyzer cargo cc-traits 2.0.0 Insert#Output#;
372 }
373
374 /// Mutable map where new new key-value pairs can be inserted.
375 pub trait MapInsertrust-analyzer cargo cc-traits 2.0.0 MapInsert#<K>: Collectionrust-analyzer cargo cc-traits 2.0.0 Collection# {
376 /// The output of the insertion function.
377 type Outputrust-analyzer cargo cc-traits 2.0.0 MapInsert#Output#;
378
379 /// Insert a new key-value pair in the collection.
380 fn insertrust-analyzer cargo cc-traits 2.0.0 MapInsert#insert().(&mut self, key: K, value: Self::Itemrust-analyzer cargo cc-traits 2.0.0 Collection#Item#) -> Self::Outputrust-analyzer cargo cc-traits 2.0.0 MapInsert#Output#;
381 }
382
383 /// Mutable collection where new elements can be pushed on the front.
384 pub trait PushFrontrust-analyzer cargo cc-traits 2.0.0 PushFront#: Collectionrust-analyzer cargo cc-traits 2.0.0 Collection# {
385 /// The output of the push function.
386 type Outputrust-analyzer cargo cc-traits 2.0.0 PushFront#Output#;
387
388 /// Push a new element on the front of the collection.
389 fn push_frontrust-analyzer cargo cc-traits 2.0.0 PushFront#push_front().(&mut self, element: Self::Itemrust-analyzer cargo cc-traits 2.0.0 Collection#Item#) -> Self::Outputrust-analyzer cargo cc-traits 2.0.0 PushFront#Output#;
390 }
391
392 /// Mutable collection where new elements can be pushed on the back.
393 pub trait PushBackrust-analyzer cargo cc-traits 2.0.0 PushBack#: Collectionrust-analyzer cargo cc-traits 2.0.0 Collection# {
394 /// The output of the push function.
395 type Outputrust-analyzer cargo cc-traits 2.0.0 PushBack#Output#;
396
397 /// Push a new element on the back of the collection.
398 fn push_backrust-analyzer cargo cc-traits 2.0.0 PushBack#push_back().(&mut self, element: Self::Itemrust-analyzer cargo cc-traits 2.0.0 Collection#Item#) -> Self::Outputrust-analyzer cargo cc-traits 2.0.0 PushBack#Output#;
399 }
400
401 /// Mutable collection where elements can be removed from.
402 pub trait Removerust-analyzer cargo cc-traits 2.0.0 Remove#<T>: Collectionrust-analyzer cargo cc-traits 2.0.0 Collection# {
403 /// Remove the element identified by the given `key`.
404 fn removerust-analyzer cargo cc-traits 2.0.0 Remove#remove().(&mut self, key: T) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self::Itemrust-analyzer cargo cc-traits 2.0.0 Collection#Item#>;
405 }
406
407 /// Mutable collection where elements can be popped from the front.
408 pub trait PopFrontrust-analyzer cargo cc-traits 2.0.0 PopFront#: Collectionrust-analyzer cargo cc-traits 2.0.0 Collection# {
409 /// Remove the front element of the collection and return it (if any).
410 fn pop_frontrust-analyzer cargo cc-traits 2.0.0 PopFront#pop_front().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self::Itemrust-analyzer cargo cc-traits 2.0.0 Collection#Item#>;
411 }
412
413 /// Mutable collection where elements can be popped from the back.
414 pub trait PopBackrust-analyzer cargo cc-traits 2.0.0 PopBack#: Collectionrust-analyzer cargo cc-traits 2.0.0 Collection# {
415 /// Remove the back element of the collection and return it (if any).
416 fn pop_backrust-analyzer cargo cc-traits 2.0.0 PopBack#pop_back().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self::Itemrust-analyzer cargo cc-traits 2.0.0 Collection#Item#>;
417 }
418
419 /// Clearable collection.
420 pub trait Clearrust-analyzer cargo cc-traits 2.0.0 Clear# {
421 /// Remove all the elements of the collection.
422 fn clearrust-analyzer cargo cc-traits 2.0.0 Clear#clear().(&mut self);
423 }
424
425 /// Iterable collection.
426 pub trait Iterrust-analyzer cargo cc-traits 2.0.0 Iter#: CollectionRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef# {
427 /// Iterator type.
428 type Iterrust-analyzer cargo cc-traits 2.0.0 Iter#Iter#<'a>: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Self::ItemRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#ItemRef#<'a>>
429 where
430 Self: 'a;
431
432 /// Create an iterator over the items of the collection.
433 fn iterrust-analyzer cargo cc-traits 2.0.0 Iter#iter().(&self) -> Self::Iterrust-analyzer cargo cc-traits 2.0.0 Iter#Iter#<'_>;
434 }
435
436 /// Mutably iterable collection.
437 pub trait IterMutrust-analyzer cargo cc-traits 2.0.0 IterMut#: CollectionMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut# {
438 /// Iterator type.
439 type IterMutrust-analyzer cargo cc-traits 2.0.0 IterMut#IterMut#<'a>: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Self::ItemMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#ItemMut#<'a>>
440 where
441 Self: 'a;
442
443 /// Create an iterator over the mutable items of the collection.
444 fn iter_mutrust-analyzer cargo cc-traits 2.0.0 IterMut#iter_mut().(&mut self) -> Self::IterMutrust-analyzer cargo cc-traits 2.0.0 IterMut#IterMut#<'_>;
445 }
446
447 pub trait MapIterrust-analyzer cargo cc-traits 2.0.0 MapIter#: KeyedRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef# + CollectionRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef# {
448 type Iterrust-analyzer cargo cc-traits 2.0.0 MapIter#Iter#<'a>: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (Self::KeyRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef#KeyRef#<'a>, Self::ItemRefrust-analyzer cargo cc-traits 2.0.0 CollectionRef#ItemRef#<'a>)>
449 where
450 Self: 'a;
451
452 fn iterrust-analyzer cargo cc-traits 2.0.0 MapIter#iter().(&self) -> Self::Iterrust-analyzer cargo cc-traits 2.0.0 MapIter#Iter#<'_>;
453 }
454
455 pub trait MapIterMutrust-analyzer cargo cc-traits 2.0.0 MapIterMut#: KeyedRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef# + CollectionMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut# {
456 type IterMutrust-analyzer cargo cc-traits 2.0.0 MapIterMut#IterMut#<'a>: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = (Self::KeyRefrust-analyzer cargo cc-traits 2.0.0 KeyedRef#KeyRef#<'a>, Self::ItemMutrust-analyzer cargo cc-traits 2.0.0 CollectionMut#ItemMut#<'a>)>
457 where
458 Self: 'a;
459
460 fn iter_mutrust-analyzer cargo cc-traits 2.0.0 MapIterMut#iter_mut().(&mut self) -> Self::IterMutrust-analyzer cargo cc-traits 2.0.0 MapIterMut#IterMut#<'_>;
461 }