reliakit-collections
Bounded and reliability-oriented collection types for Rust.
reliakit-collections provides collection types with enforced size constraints. Bounds are expressed as const generic parameters and checked at construction time. Mutations that would violate the bounds return errors instead of panicking.
The crate has no dependencies and forbids unsafe code.
When To Use It
Use this crate when:
- a list must always have at least one element,
- a list must not exceed a known maximum size,
- you want mutation operations to be safe-by-default rather than checked at the call site,
- you are modeling domain concepts like a non-empty recipient list, a capped queue, or a fixed-size batch.
When Not To Use It
Do not use this crate as a replacement for:
- runtime-sized collections without known bounds — use
std::collectionsdirectly, - fixed-size stack-allocated arrays — use
[T; N], NonEmptyVec<T>with no upper bound — that type is already inreliakit-primitives.
Installation
[]
= "0.1"
For no_std environments:
[]
= { = "0.1", = false, = ["alloc"] }
Examples
Bounded recipient list
use BoundedVec;
type RecipientList = ;
let mut recipients = new.unwrap;
recipients.push.unwrap;
assert_eq!;
Push and pop with bound enforcement
use BoundedVec;
let mut v = new.unwrap;
assert!; // at capacity
assert_eq!;
assert!; // len = 2, above minimum
assert!; // would go below minimum (1)
Exact-size collection
use BoundedVec;
// Must have exactly 3 elements
type Triple = ;
assert!;
assert!;
assert!;
Available Types
| Type | Description |
|---|---|
BoundedVec<T, MIN, MAX> |
Vec<T> constrained to hold between MIN and MAX elements |
Feature Flags
| Flag | Default | Description |
|---|---|---|
std |
yes | Enables std::error::Error for CollectionError |
alloc |
no | Enables BoundedVec without std |
no_std
The crate supports no_std environments when std is disabled and alloc is available.
Safety
This crate is #![forbid(unsafe_code)].
Minimum Supported Rust Version
Rust 1.85 stable. No nightly features are used.
Status
Active. Not yet published to crates.io.
Contributing
See CONTRIBUTING.md.
License
Licensed under the MIT License.