#bounds #serialization #guarantees #lower #non-empty #serde #upper-bound

bounded-vec

Non-empty rust Vec wrapper with type guarantees on lower and upper bounds for items quantity

8 breaking releases

0.9.0 Jun 5, 2025
0.8.0 Dec 2, 2024
0.7.1 Aug 1, 2022
0.7.0 Jul 26, 2022
0.3.0 Jun 9, 2021

#117 in Data structures

Download history 31280/week @ 2025-06-06 30740/week @ 2025-06-13 36736/week @ 2025-06-20 41210/week @ 2025-06-27 34757/week @ 2025-07-04 32284/week @ 2025-07-11 34778/week @ 2025-07-18 33964/week @ 2025-07-25 23972/week @ 2025-08-01 23696/week @ 2025-08-08 29443/week @ 2025-08-15 25035/week @ 2025-08-22 38124/week @ 2025-08-29 34839/week @ 2025-09-05 34731/week @ 2025-09-12 39359/week @ 2025-09-19

152,832 downloads per month
Used in 112 crates (9 directly)

CC0 license

30KB
514 lines

Coverage Status Latest Version Documentation

bounded-vec

BoundedVec<T, L, U> - Non-empty rust std::vec::Vec wrapper with type guarantees on lower(L) and upper(U) bounds for items quantity. Inspired by vec1.

This crate is #![no_std] compatible with alloc.

Example

use bounded_vec::BoundedVec;

let data: BoundedVec<u8, 2, 4> = [1u8,2].into();

assert_eq!(*data.first(), 1);
assert_eq!(*data.last(), 2);

// creates a new BoundedVec by mapping each element
let data = data.mapped(|x|x*2);
assert_eq!(data, [2u8,4].into());

Crate features

  • optional(non-default) serde feature that adds serialization to BoundedVec.
  • optional(non-default) schema feature that adds JSON schema support via schemars (requires serde).
  • optional(non-default) arbitrary feature that adds proptest::Arbitrary implementation to BoundedVec.

Changelog

See CHANGELOG.md.

Contributing

See Contributing guide.

Dependencies

~0.2–1.3MB
~26K SLoC