#[unsafe(no_mangle)]pub unsafe extern "C" fn nstd_vec_push(
vec: &mut NSTDVec<'_>,
value: NSTDAny,
) -> NSTDAllocErrorAvailable on crate feature
vec only.Expand description
Pushes a value onto a vector by copying bytes to the end of the vector’s buffer. The number of
bytes to push is determined by vec’s stride.
§Parameters:
-
NSTDVec *vec- The vector. -
NSTDAny value- A pointer to the value to push onto the vector.
§Returns
NSTDAllocError errc - The allocation operation error code.
§Safety
This operation is unsafe because undefined behavior can occur if the size of the value being
pushed onto the vector is not equal to vec’s stride.
§Example
use core::ptr::addr_of;
use nstd_sys::{
alloc::NSTD_ALLOCATOR,
vec::{nstd_vec_new, nstd_vec_push},
};
const SIZE: usize = core::mem::size_of::<f64>();
const ALIGN: usize = core::mem::size_of::<f64>();
unsafe {
let mut vec = nstd_vec_new(&NSTD_ALLOCATOR, SIZE, ALIGN);
let values: [f64; 3] = [6.0, 3.1, 9.4];
for value in values {
nstd_vec_push(&mut vec, addr_of!(value).cast());
}
}