Trait kernel::alloc::vec_ext::VecExt

source ·
pub trait VecExt<T>: Sized {
    // Required methods
    fn with_capacity(capacity: usize, flags: Flags) -> Result<Self, AllocError>;
    fn push(&mut self, v: T, flags: Flags) -> Result<(), AllocError>;
    fn extend_from_slice(
        &mut self,
        other: &[T],
        flags: Flags
    ) -> Result<(), AllocError>
       where T: Clone;
    fn reserve(
        &mut self,
        additional: usize,
        flags: Flags
    ) -> Result<(), AllocError>;
}
Expand description

Extensions to Vec.

Required Methods§

source

fn with_capacity(capacity: usize, flags: Flags) -> Result<Self, AllocError>

Creates a new Vec instance with at least the given capacity.

§Examples
let v = Vec::<u32>::with_capacity(20, GFP_KERNEL)?;

assert!(v.capacity() >= 20);
source

fn push(&mut self, v: T, flags: Flags) -> Result<(), AllocError>

Appends an element to the back of the Vec instance.

§Examples
let mut v = Vec::new();
v.push(1, GFP_KERNEL)?;
assert_eq!(&v, &[1]);

v.push(2, GFP_KERNEL)?;
assert_eq!(&v, &[1, 2]);
source

fn extend_from_slice( &mut self, other: &[T], flags: Flags ) -> Result<(), AllocError>
where T: Clone,

Pushes clones of the elements of slice into the Vec instance.

§Examples
let mut v = Vec::new();
v.push(1, GFP_KERNEL)?;

v.extend_from_slice(&[20, 30, 40], GFP_KERNEL)?;
assert_eq!(&v, &[1, 20, 30, 40]);

v.extend_from_slice(&[50, 60], GFP_KERNEL)?;
assert_eq!(&v, &[1, 20, 30, 40, 50, 60]);
source

fn reserve(&mut self, additional: usize, flags: Flags) -> Result<(), AllocError>

Ensures that the capacity exceeds the length by at least additional elements.

§Examples
let mut v = Vec::new();
v.push(1, GFP_KERNEL)?;

v.reserve(10, GFP_KERNEL)?;
let cap = v.capacity();
assert!(cap >= 10);

v.reserve(10, GFP_KERNEL)?;
let new_cap = v.capacity();
assert_eq!(new_cap, cap);

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T> VecExt<T> for Vec<T>

source§

fn with_capacity(capacity: usize, flags: Flags) -> Result<Self, AllocError>

source§

fn push(&mut self, v: T, flags: Flags) -> Result<(), AllocError>

source§

fn extend_from_slice( &mut self, other: &[T], flags: Flags ) -> Result<(), AllocError>
where T: Clone,

source§

fn reserve(&mut self, additional: usize, flags: Flags) -> Result<(), AllocError>

Implementors§