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
This crate covers bounded collection types. The following are out of scope:
- runtime-sized collections without known bounds, served by
std::collections, - fixed-size stack-allocated arrays, served by
[T; N], - unbounded non-empty vectors, which
reliakit-primitivesalready provides asNonEmptyVec<T>.
Installation
[]
= "0.2"
For no_std environments:
[]
= { = "0.2", = 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; implies alloc |
alloc |
no | Enables BoundedVec (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.
Safety
This crate is #![forbid(unsafe_code)].
Minimum Supported Rust Version
Rust 1.85 stable. No nightly features are used.
Status
Active. The 0.1.x API is considered stable.
Contributing
See CONTRIBUTING.md.
License
Licensed under the MIT License.