Function nstd_sys::vec::nstd_vec_pop
source · Available on crate feature
nstd_vec only.Expand description
Removes the last value of a vector and returns a pointer to it.
Note
It is highly advised to copy the return value onto the stack because the pointer can easily become invalid if the vector is mutated.
Parameters:
NSTDVec *vec- The vector.
Returns
NSTDAny value- A pointer to the value that was popped off the stack, or null if the vector is empty.
Panics
Panics if vec’s new length (in bytes) exceeds NSTDInt’s max value.
Example
use core::ptr::addr_of;
use nstd_sys::{
core::slice::nstd_core_slice_new,
vec::{nstd_vec_extend, nstd_vec_new, nstd_vec_pop},
};
const SIZE: usize = core::mem::size_of::<f64>();
let mut vec = nstd_vec_new(SIZE);
let values: [f64; 3] = [9.4, 3.1, 6.0];
let values_slice = nstd_core_slice_new(values.as_ptr().cast(), SIZE, 3);
unsafe {
nstd_vec_extend(&mut vec, &values_slice);
for value in values.iter().rev() {
assert!(*value == *nstd_vec_pop(&mut vec).cast::<f64>());
}
}