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
//! Bounded and reliability-oriented collection types for Rust.
//!
//! `reliakit-collections` provides collection types with enforced size
//! constraints. The bounds are expressed as const generic parameters and
//! checked at construction time. Mutations that would violate the bounds
//! return errors rather than panicking.
//!
//! # Types
//!
//! - [`BoundedVec<T, MIN, MAX>`] — an owned `Vec<T>` constrained to hold
//! between `MIN` and `MAX` elements inclusive.
//! - [`BoundedMap<K, V, MIN, MAX>`] — an insertion-ordered key-value map with
//! unique keys and an enforced entry-count range.
//! - [`BoundedSet<T, MIN, MAX>`] — an insertion-ordered set of unique elements
//! with an enforced count range.
//! - [`RingBuffer<T>`] — a fixed-capacity circular buffer that overwrites the
//! oldest element when full (a rolling window that never fails to push).
//!
//! [`BoundedMap`] and [`BoundedSet`] are backed by a `Vec` and use linear scans
//! for lookup, so they stay deterministic and dependency-free (no hashing or
//! ordering machinery) and are meant for the small, bounded sizes their bounds
//! describe.
//!
//! # Examples
//!
//! ```
//! use reliakit_collections::BoundedVec;
//!
//! // A list that must have between 1 and 10 recipients
//! type RecipientList = BoundedVec<String, 1, 10>;
//!
//! let mut recipients = RecipientList::new(vec!["alice@example.com".into()]).unwrap();
//! recipients.push("bob@example.com".into()).unwrap();
//! assert_eq!(recipients.len(), 2);
//! ```
//!
//! Mutations that would violate bounds are rejected:
//!
//! ```
//! use reliakit_collections::BoundedVec;
//!
//! let mut v = BoundedVec::<i32, 1, 2>::new(vec![1, 2]).unwrap();
//! assert!(v.push(3).is_err()); // at capacity
//! assert!(v.pop().is_ok()); // still above minimum
//! assert!(v.pop().is_err()); // would go below minimum
//! ```
//!
//! # Feature flags
//!
//! - `std` (default) enables `std::error::Error` for [`CollectionError`] and
//! implies `alloc`.
//! - `alloc` enables [`BoundedVec`], which is backed by `Vec<T>`.
//!
//! # `no_std`
//!
//! The crate supports `no_std`. [`BoundedVec`] requires the `alloc` feature
//! (enabled by default via `std`). The error types ([`CollectionError`],
//! [`CollectionResult`]) are available without `alloc`.
extern crate alloc;
pub use BoundedMap;
pub use BoundedSet;
pub use BoundedVec;
pub use ;
pub use RingBuffer;