Expand description
Dynamically resizable arrays
This module provides abstractions around VPP’s vector type, which is a
dynamically resizable array similar to Rust’s Vec<T>.
§Memory layout
+-------------------+----------------+----------------+----------------+
| vec_header_t hdr | T elem[0] | T elem[1] | T elem[2] | ...
+-------------------+----------------+----------------+----------------+
^
+---------------- User pointer§Relationship between Vec<T> and VecRef<T>
The Vec<T> type is an owning vector type that manages the memory
allocation and deallocation for the vector. It provides methods for
modifying the vector, such as push, pop, and insert_mut.
The VecRef<T> type is a non-owning reference type that provides
read-only access to the elements of the vector. It is used when
you want to pass around a reference to a vector without taking ownership of it.
Note that there may be some times when you don’t own the vector, but you need to perform operations which may resize it, such as to push an element. Be careful about updating the original pointer because if the vector is resized the pointer may change and the original pointer may no longer be valid. In these cases, you can temporarily take ownership of the vector by doing:
use vpp_plugin::vppinfra::vec::Vec;
let mut v = unsafe { Vec::from_raw(ptr) };
v.push(1);
ptr = v.into_raw();Structs§
- Into
Iter - An iterator that moves out of a vector.
- Vec
- Owned dynamically resizable array
- VecRef
- Reference to a dynamically resizable array
Traits§
- Slice
Ext - Extension trait for slices to convert to VPP vectors