nstd_vec_extend

Function nstd_vec_extend 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nstd_vec_extend( vec: &mut NSTDVec<'_>, values: &NSTDSlice, ) -> NSTDAllocError
Available on crate feature 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 if vec and values strides do not match.

§Safety

This operation can cause undefined behavior if values’s data is invalid.

§Example

use nstd_sys::{
    alloc::NSTD_ALLOCATOR,
    core::{alloc::NSTDAllocError::NSTD_ALLOC_ERROR_NONE, slice::nstd_core_slice_new},
    vec::{nstd_vec_extend, nstd_vec_get, nstd_vec_new},
};

const SIZE: usize = core::mem::size_of::<i128>();
const ALIGN: usize = core::mem::align_of::<i128>();

unsafe {
    let values: [i128; 5] = [1, 2, 3, 4, 5];
    let slice = nstd_core_slice_new(values.as_ptr().cast(), SIZE, ALIGN, 5).unwrap();
    let mut vec = nstd_vec_new(&NSTD_ALLOCATOR, SIZE, ALIGN);
    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]);
    }
}