macro_rules! fixed_vec {
() => { ... };
($($elem:expr),+ $(,)?) => { ... };
($elem:expr; $len:expr) => { ... };
}
Expand description
Creates a FixedVec
with default parameters.
This macro simplifies the creation of FixedVec
by using default parameters
(usize
for the storage word, LittleEndian
for byte order) inferred
from the element type. It uses BitWidth::Minimal
for space efficiency.
There are three forms of this macro:
-
Create a vector from a list of elements:
let vec = fixed_vec![10u32, 20, 30];
-
Create a vector from a repeated element:
let vec = fixed_vec![0i16; 100];
-
Create an empty vector (the element type must be specified):
let vec: UFixedVec<u32> = fixed_vec![];
ยงExamples
use compressed_intvec::fixed_vec;
use compressed_intvec::fixed::UFixedVec;
// Create a vector from a list of elements.
let vec = fixed_vec![10u32, 20, 30];
assert_eq!(vec.len(), 3);
assert_eq!(vec.bit_width(), 5); // 30 requires 5 bits
// Create a vector from a repeated element.
let vec_rep = fixed_vec![0i16; 100];
assert_eq!(vec_rep.len(), 100);
assert_eq!(vec_rep.get(50), Some(0));
// Create an empty vector (type annotation is required).
let empty: UFixedVec<u64> = fixed_vec![];
assert!(empty.is_empty());