#[repr(C)]pub struct CVec {
pub ptr: *mut c_void,
pub len: usize,
pub cap: usize,
}Expand description
CVec is a C compatible struct that stores an opaque pointer to a block of
memory, its length and the capacity of the vector it was allocated from.
§Safety
Changing the values here may lead to undefined behavior when the memory is dropped.
Fields§
§ptr: *mut c_voidOpaque pointer to block of memory storing elements to access the elements cast it to the underlying type.
len: usizeThe number of elements in the block.
cap: usizeThe capacity of vector from which it was allocated. Used when deallocating the memory
Implementations§
Source§impl CVec
impl CVec
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Returns an empty CVec.
This is primarily useful for constructing a sentinel value that represents the absence of data when crossing the FFI boundary.
Uses a dangling pointer (like Vec::new()) rather than null to satisfy
Vec::from_raw_parts preconditions when the CVec is later dropped.
Trait Implementations§
impl Copy for CVec
Source§impl<T> From<Vec<T>> for CVec
Consumes and leaks the Vec, returning a mutable pointer to the contents as
a CVec. The memory has been leaked and now exists for the lifetime of the
program unless dropped manually.
Note: drop the memory by reconstructing the vec using from_raw_parts method
as shown in the test below.
impl<T> From<Vec<T>> for CVec
Consumes and leaks the Vec, returning a mutable pointer to the contents as
a CVec. The memory has been leaked and now exists for the lifetime of the
program unless dropped manually.
Note: drop the memory by reconstructing the vec using from_raw_parts method
as shown in the test below.