#limit #bounds #type #bounded-vec

bounded-vector

Vec wrapper that guarantees upper and lower bounds on type level

10 releases

new 0.3.2 Mar 17, 2025
0.3.1 Mar 15, 2025
0.2.2 Mar 15, 2025
0.2.1 Apr 16, 2024
0.1.3 Apr 15, 2024

#611 in Rust patterns

Download history 3/week @ 2024-12-07 1/week @ 2024-12-14 1/week @ 2025-02-01 6/week @ 2025-02-15 4/week @ 2025-02-22 2/week @ 2025-03-01 452/week @ 2025-03-15

461 downloads per month
Used in 2 crates

MIT/Apache

63KB
801 lines

bounded-vector

crates.io

BoundedVec<T, LOW, UPP> - Vec wrapper that guarantees upper and lower bounds on type level. Alternative to bounded-vec that offers compatibility with empty vector, has more methods and bvec! that works like vec! macro.

Example

use bounded_vector::{BoundedVec, bvec};
let mut data: BoundedVec<u8, 2, 4> = [1, 2].into();

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

data.iter_mut().for_each(|x| *x *= 2);
assert_eq!(data, bvec![2, 4]);

License

Licensed under either of MIT or Apache-2.0 at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

[BoundedVec<T, LOW, UPP>] - Vec wrapper that guarantees upper and lower bounds on type level. Alternative to bounded-vec that offers compatibility with empty vector, has more methods and bvec! that works like vec! macro.

Example

#
use bounded_vector::{BoundedVec, bvec};
let mut data: BoundedVec<u8, 2, 4> = [1, 2].try_into()?;

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

data.iter_mut().for_each(|x| *x *= 2);
assert_eq!(data, bvec![2, 4]);

Dependencies

~225–730KB
~17K SLoC