Expand description
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 ownedVec<T>constrained to hold betweenMINandMAXelements 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) enablesstd::error::ErrorforCollectionErrorand impliesalloc.allocenablesBoundedVec, which is backed byVec<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.
Structs§
- Bounded
Map - Owned key-value map constrained by inclusive entry-count bounds.
- Bounded
Set - Owned set of unique elements constrained by inclusive count bounds.
- Bounded
Vec - Owned vector constrained by inclusive element count bounds.
- Ring
Buffer - A fixed-capacity circular buffer that overwrites the oldest element when full.
Enums§
- Collection
Error - Error returned by bounded collection operations.
Type Aliases§
- Collection
Result - Result alias for bounded collection operations.