Crate sized_vec[][src]

Type Level Sized Vectors

This crate provides a Vec<N, A> type, which wraps the standard Vec<A> and tracks its size N at the type level.

Because the size is embedded in the type, we can do things like verifying at compile time that index lookups are within bounds.

This example deliberately fails to compile
let vec = svec![1, 2, 3];
// This index lookup won't compile, because index `U8` is outside
// the vector's length of `U3`:
assert_eq!(5, vec[U8::new()]);
let vec = svec![1, 2, 3];
// On the other hand, this lookup can be verified to be correct
// by the type system:
assert_eq!(3, vec[U2::new()]);

Limitations

If this looks too good to be true, it's because it comes with a number of limitations: you won't be able to perform operations on the vector which could leave it with a length that can't be known at compile time. This includes, notably, FromIterator::from_iter(), Extend::extend(), and filtering operations like Vec::retain().

Macros

svec

Structs

Range

A type level range.

Vec

A vector of length N containing elements of type A.

Traits

IsTrue