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;
}
zerocopy-08
only.Expand description
Extension trait for this crate’s vector types.
Required Associated Types§
Required Methods§
Sourcefn extend_zeroed(&mut self, additional: usize)
fn extend_zeroed(&mut self, additional: usize)
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 ≎ 1, 2, 3];
vec.extend_zeroed(2);
assert_eq!(vec, [1, 2, 3, 0, 0]);
Sourcefn try_extend_zeroed(&mut self, additional: usize) -> Result<(), AllocError>
fn try_extend_zeroed(&mut self, additional: usize) -> Result<(), AllocError>
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 ≎ 1, 2, 3]?;
vec.try_extend_zeroed(2)?;
assert_eq!(vec, [1, 2, 3, 0, 0]);
Sourcefn resize_zeroed(&mut self, new_len: usize)
fn resize_zeroed(&mut self, new_len: usize)
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 ≎ 1, 2, 3];
vec.resize_zeroed(5);
assert_eq!(vec, [1, 2, 3, 0, 0]);
let mut vec = bump_vec![in ≎ 1, 2, 3];
vec.resize_zeroed(2);
assert_eq!(vec, [1, 2]);
Sourcefn try_resize_zeroed(&mut self, new_len: usize) -> Result<(), AllocError>
fn try_resize_zeroed(&mut self, new_len: usize) -> Result<(), AllocError>
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 ≎ 1, 2, 3]?;
vec.try_resize_zeroed(5)?;
assert_eq!(vec, [1, 2, 3, 0, 0]);
let mut vec = bump_vec![try in ≎ 1, 2, 3]?;
vec.try_resize_zeroed(2)?;
assert_eq!(vec, [1, 2]);