aztec-nr - noir_aztec::utils::array::subbvec

Function subbvec

pub fn subbvec<T, let SrcMaxLen: u32, let DstMaxLen: u32>(
    bvec: BoundedVec<T, SrcMaxLen>,
    offset: u32,
) -> BoundedVec<T, DstMaxLen>

Returns DstMaxLen elements from a source BoundedVec, starting at offset. offset must not be larger than the original length, and DstLen must not be larger than the total number of elements past offset (including the zeroed elements past len()).

Only elements at the beginning of the vector can be removed: it is not possible to also remove elements at the end of the vector by passing a value for DstLen that is smaller than len() - offset.

Examples:

let foo = BoundedVec::<_, 10>::from_array([1, 2, 3, 4, 5]);
assert_eq(subbvec(foo, 2), BoundedVec::<_, 8>::from_array([3, 4, 5]));

let bar: BoundedVec<_, 1> = subbvec(foo, 2); // fails - we can't return just 1 element since 3 remain
let baz: BoundedVec<_, 10> = subbvec(foo, 3); // fails - we can't return 10 elements since only 7 remain