Vec
.
This trait extends the read functionality with methods to append new elements
and modify existing ones.
None
if out of
bounds.
append
function, which allowed
appending new elements to a vector.
Unlike push
, which gets an object to write to the vector, allocate
is specifically
useful when you need to prepare space for elements of unknown or dynamic size (e.g.,
appending another vector).
allocate
is essential when pushing a vector into another vector, as the size of the
nested vector is unknown at compile time. It allows the caller to allocate the required
space first, then write the nested vector into the allocated space using .write()
.
This is necessary because pushing directly (e.g., vec.push(nested_vec)
) is not supported
due to Vec
being only a storage abstraction.
append
function is now deprecated. Use allocate
to achieve the same functionality
with improved clarity and flexibility.
allocate
instead.
None
if the vector is empty.