Function nstd_sys::vec::nstd_vec_extend
source · #[no_mangle]
pub unsafe extern "C" fn nstd_vec_extend(
vec: &mut NSTDVec,
values: &NSTDSlice
) -> NSTDAllocErrorAvailable on crate feature
nstd_vec only.Expand description
Pushes a series of values onto a vector.
Parameters:
-
NSTDVec *vec- The vector to extend. -
const NSTDSlice *values- A slice of values to push onto the vector.
Returns
NSTDAllocError errc - The allocation operation error code.
Panics
This operation will panic in the following situations:
-
vecandvaluesstrides do not match. -
The current length in bytes exceeds
NSTDInt’s max value.
Safety
This operation can cause undefined behavior if values’s data is invalid.
Example
use nstd_sys::{
alloc::NSTDAllocError::NSTD_ALLOC_ERROR_NONE,
core::slice::nstd_core_slice_new,
vec::{nstd_vec_extend, nstd_vec_get, nstd_vec_new},
};
const SIZE: usize = core::mem::size_of::<i128>();
let values: [i128; 5] = [1, 2, 3, 4, 5];
let slice = nstd_core_slice_new(values.as_ptr().cast(), SIZE, 5);
unsafe {
let mut vec = nstd_vec_new(SIZE);
assert!(nstd_vec_extend(&mut vec, &slice) == NSTD_ALLOC_ERROR_NONE);
for i in 0..5 {
let v = nstd_vec_get(&vec, i);
assert!(!v.is_null());
assert!(*v.cast::<i128>() == values[i]);
}
}