devela/data/collections/destaque/
definitions.rs

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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// devela::data::collections::destaque::definitions
//
//! Double-ended queues are linear lists for which any accesses are made from
//! either end.
//

use crate::{Array, Bare, Storage};
#[cfg(feature = "dep_rkyv")]
use rkyv::{Archive, Deserialize, Serialize};

/* types */

/// A static double-ended queue and stack backed by an [`Array`].
///
/// It is generic in respect to its
/// elements (`T`),
/// capacity (`CAP`),
/// index size (`IDX`)
/// and storage (`S`).
///
/// The index size will upper-bound the capacity to the maximum for that type,
/// e.g. `u8::MAX` for [`DestaqueU8`].
///
/// The index size determines the maximum possible number of elements in the destaque,
/// thereby upper-bounding the capacity to the maximum value representable by the
/// index type. For example, `u8::MAX` for [`DestaqueU8`].
///
/// The total size in bytes of the stack may be influenced by the chosen index
/// size, depending on the size and alignment of the elements. This difference
/// could only be significant for small capacities, as only one index is stored.
///
/// See also the related aliases that specify `IDX`:
#[cfg_attr(not(feature = "_destaque_all"), allow(rustdoc::broken_intra_doc_links))]
/// [`DestaqueU8`], [`DestaqueU16`], [`DestaqueU32`], [`DestaqueUsize`],
/// and the related traits:
/// [`DataQueue`][crate::DataQueue], [`DataDeque`][crate::DataDeque],
/// [`DataStack`][crate::DataStack], [`DataDesta`][crate::DataDesta].<br/>
///
/// ## Methods
///
/// It implements methods that operate from both the front and the back.
/// Rememeber that a single-ended *stack* operates only from the back, while a
/// single-ended *queue* pushes to the back and pops from the front.
///
/// - General methods:
///   - [`new`][Self::new],
/// [`len`][Self::len], [`is_empty`][Self::is_empty], [`is_full`][Self::is_full],
/// [`clear`][Self::clear], [`contains`][Self::contains],
/// [`capacity`][Self::capacity], [`remaining_capacity`][Self::remaining_capacity].
///   - [`iter`][Self::iter],
/// [`extend_back`][Self::extend_back], [`extend_front`][Self::extend_front],
/// [`from_array`][Self::from_array]*([`copy`][Self::from_array_copy])*,
/// [`to_array`][Self::to_array],
/// [`to_vec`][Self::to_vec].
///
/// - Queue and stack methods:
///   - push:
/// [`push_back`][Self::push_back]*([uc][Self::push_back_unchecked])*
///   **=** [`enqueue`][Self::enqueue],
/// [`push_front`][Self::push_front]*([uc][Self::push_front_unchecked])*.
///   - pop:
/// [`pop_front`][Self::pop_front]
///   **=** [`dequeue`][Self::dequeue],
/// [`pop_back`][Self::pop_back].
///   - peek:
/// [`peek_back`][Self::peek_back]*([mut][Self::peek_back_mut])*
/// [`peek_nth_back`][Self::peek_nth_back]*([mut][Self::peek_nth_back_mut])*,
/// [`peek_front`][Self::peek_front]*([mut][Self::peek_front_mut])*,
/// [`peek_nth_front`][Self::peek_nth_front]*([mut][Self::peek_nth_front_mut])*.
///   - drop:
/// [`drop_back`][Self::drop_back],
/// [`drop_front`][Self::drop_front],
/// [`drop_n_back`][Self::drop_n_back],
/// [`drop_n_front`][Self::drop_n_front].
///   - swap:
/// [`swap_back`][Self::swap_back]*([uc][Self::swap_back_unchecked])*,
/// [`swap_front`][Self::swap_front]*([uc][Self::swap_front_unchecked])*,
/// [`swap2_back`][Self::swap2_back]*([uc][Self::swap2_back_unchecked])*,
/// [`swap2_front`][Self::swap2_front]*([uc][Self::swap2_front_unchecked])*,
/// [`swap_ends`][Self::swap_ends], [`swap2_ends`][Self::swap2_ends].
///   - rot:
/// [`rot_right`][Self::rot_right],
/// [`rot_right_n`][Self::rot_right_n],
/// [`rot_left`][Self::rot_left],
/// [`rot_left_n`][Self::rot_left_n].
///   - dup:
/// [`dup_back`][Self::dup_back],
/// [`dup_front`][Self::dup_front],
/// [`dup2_back`][Self::dup2_back],
/// [`dup2_front`][Self::dup2_front].
///   - over:
/// [`over_back`][Self::over_back],
/// [`over_front`][Self::over_front],
/// [`over2_back`][Self::over2_back],
/// [`over2_front`][Self::over2_front].
///   - tuck:
/// [`tuck_back`][Self::tuck_back],
/// [`tuck_front`][Self::tuck_front],
/// [`tuck2_back`][Self::tuck2_back],
/// [`tuck2_front`][Self::tuck2_front].
#[cfg_attr(feature = "dep_rkyv", derive(Archive, Serialize, Deserialize))]
pub struct Destaque<T, const CAP: usize, IDX, S: Storage = Bare> {
    pub(super) data: Array<T, CAP, S>,
    pub(super) len: IDX,
    pub(super) front: IDX,
    pub(super) back: IDX,
}

/// A [`Destaque`] with an 8-bit index size.
#[cfg(feature = "_destaque_u8")]
#[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "_destaque_u8")))]
pub type DestaqueU8<T, const CAP: usize, S = Bare> = Destaque<T, CAP, u8, S>;

/// A [`Destaque`] with a 16-bit index size.
#[cfg(feature = "_destaque_u16")]
#[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "_destaque_u16")))]
pub type DestaqueU16<T, const CAP: usize, S = Bare> = Destaque<T, CAP, u16, S>;

/// A [`Destaque`] with a 32-bit index size.
#[cfg(feature = "_destaque_u32")]
#[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "_destaque_u32")))]
pub type DestaqueU32<T, const CAP: usize, S = Bare> = Destaque<T, CAP, u32, S>;

/// A [`Destaque`] with a pointer-sized index size.
#[cfg(feature = "_destaque_usize")]
#[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "_destaque_usize")))]
pub type DestaqueUsize<T, const CAP: usize, S = Bare> = Destaque<T, CAP, usize, S>;

/* iterators */

#[doc = crate::TAG_ITERATOR!()]
/// An iterator over [`Destaque`] elements.
pub struct DestaqueIter<'s, T, const CAP: usize, IDX, S: Storage = Bare> {
    pub(super) destaque: &'s Destaque<T, CAP, IDX, S>,
    pub(super) idx: usize,
}