VecExt

Trait VecExt 

Source
pub trait VecExt: Sealed {
    type T;

    // Required methods
    fn extend_zeroed(&mut self, additional: usize)
       where Self::T: FromZeros;
    fn try_extend_zeroed(&mut self, additional: usize) -> Result<(), AllocError>
       where Self::T: FromZeros;
    fn resize_zeroed(&mut self, new_len: usize)
       where Self::T: FromZeros;
    fn try_resize_zeroed(&mut self, new_len: usize) -> Result<(), AllocError>
       where Self::T: FromZeros;
}
Available on crate feature zerocopy-08 only.
Expand description

Extension trait for this crate’s vector types.

Required Associated Types§

Source

type T

The element type of this vector.

Required Methods§

Source

fn extend_zeroed(&mut self, additional: usize)
where Self::T: FromZeros,

Extends this vector by pushing additional new items onto the end. The new items are initialized with zeroes.

§Panics

Panics if the allocation fails.

§Examples
use bump_scope::{Bump, bump_vec, zerocopy_08::VecExt};
let bump: Bump = Bump::new();

let mut vec = bump_vec![in &bump; 1, 2, 3];
vec.extend_zeroed(2);
assert_eq!(vec, [1, 2, 3, 0, 0]);
Source

fn try_extend_zeroed(&mut self, additional: usize) -> Result<(), AllocError>
where Self::T: FromZeros,

Extends this vector by pushing additional new items onto the end. The new items are initialized with zeroes.

§Errors

Errors if the allocation fails.

§Examples
use bump_scope::{Bump, bump_vec, zerocopy_08::VecExt};
let bump: Bump = Bump::try_new()?;

let mut vec = bump_vec![try in &bump; 1, 2, 3]?;
vec.try_extend_zeroed(2)?;
assert_eq!(vec, [1, 2, 3, 0, 0]);
Source

fn resize_zeroed(&mut self, new_len: usize)
where Self::T: FromZeros,

Resizes this vector in-place so that len is equal to new_len.

If new_len is greater than len, the vector is extended by the difference, with each additional slot filled with value. If new_len is less than len, the vector is simply truncated.

§Panics

Panics if the allocation fails.

§Examples
use bump_scope::{Bump, bump_vec, zerocopy_08::VecExt};
let bump: Bump = Bump::new();

let mut vec = bump_vec![in &bump; 1, 2, 3];
vec.resize_zeroed(5);
assert_eq!(vec, [1, 2, 3, 0, 0]);

let mut vec = bump_vec![in &bump; 1, 2, 3];
vec.resize_zeroed(2);
assert_eq!(vec, [1, 2]);
Source

fn try_resize_zeroed(&mut self, new_len: usize) -> Result<(), AllocError>
where Self::T: FromZeros,

Resizes this vector in-place so that len is equal to new_len.

If new_len is greater than len, the vector is extended by the difference, with each additional slot filled with value. If new_len is less than len, the vector is simply truncated.

§Errors

Errors if the allocation fails.

§Examples
use bump_scope::{Bump, bump_vec, zerocopy_08::VecExt};
let bump: Bump = Bump::try_new()?;

let mut vec = bump_vec![try in &bump; 1, 2, 3]?;
vec.try_resize_zeroed(5)?;
assert_eq!(vec, [1, 2, 3, 0, 0]);

let mut vec = bump_vec![try in &bump; 1, 2, 3]?;
vec.try_resize_zeroed(2)?;
assert_eq!(vec, [1, 2]);

Implementors§

Source§

impl<T> VecExt for FixedBumpVec<'_, T>

Source§

type T = T

Source§

impl<T, A: BumpAllocatorExt> VecExt for BumpVec<T, A>

Source§

type T = T

Source§

impl<T, A: MutBumpAllocatorExt> VecExt for MutBumpVec<T, A>

Source§

type T = T

Source§

impl<T, A: MutBumpAllocatorExt> VecExt for MutBumpVecRev<T, A>

Source§

type T = T