macro_rules! bvec {
() => { ... };
($elem:expr; $n:expr) => { ... };
($($x:expr),+ $(,)?) => { ... };
}Expand description
Macro similar to vec!
Examples
Creating BoundedVec from elements
let bvec: BoundedVec<i32, 0, 3> = bvec![1, 2, 3]?;
assert_eq!(vec![1,2,3], bvec.to_vec());Creating BoundedVec from n same elements(must have clone trait)
let bvec: BoundedVec<i32, 0, 3> = bvec![1; 3]?;
assert_eq!(vec![1,1,1], bvec.to_vec());Macro gives Error for first two usages if element count don’t fit bounds
let bvec: Result<BoundedVec<i32, 0, 0>, _> = bvec![1];
assert_eq!(bvec, Err(Error::OutOfBoundsVec));Creating empty BoundedVec<_, 0, _>. This usage does not return Result because it ensures correct bounds at the compile time
let bvec: BoundedVec<i32, 0, 0> = bvec![];
assert_eq!(BoundedVec::new(), bvec);