Struct rkyv::util::ScratchVec [−][src]
pub struct ScratchVec<T> { /* fields omitted */ }
Expand description
A vector view into serializer scratch space.
Implementations
Constructs a new, empty ScratchVec
with the specified capacity.
The vector will be able to hold exactly capacity
elements. If capacity
is 0, the vector
will not allocate.
Safety
- The vector must not outlive the given scratch space.
- Vectors must be dropped in the reverse order they are allocated.
Frees the memory associated with the scratch vec and releases it back to the scratch space.
This must be called when serialization succeeds, but may be omitted when serialization fails. In that case, the elements of the scratch vec will be dropped but the memory will not be popped. It is the duty of the scratch space in that case to ensure that memory resources are properly cleaned up.
Safety
The given scratch space must be the same one used to allocate the scratch vec.
Clears the vector, removing all values.
Note that this method has no effect on the allocated capacity of the vector.
Returns an unsafe mutable pointer to the vector’s buffer.
The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage.
Extracts a mutable slice of the entire vector.
Equivalent to &mut s[..]
.
Returns a raw pointer to the vector’s buffer.
The caller must ensure that the vector outlives the pointer this functions returns, or else it will end up pointing to garbage.
The caller must also ensure that the memory the pointer (non-transitively) points to is
never written to (except inside an UnsafeCell
) using this pointer or any pointer derived
from it. If you need to mutate the contents of the slice, use
as_mut_ptr
.
Extracts a slice containing the entire vector.
Equivalent to &s[..]
.
Returns the number of elements the vector can hole without reallocating.
Ensures that there is capacity for at least additional
more elements to be inserted into
the ScratchVec
.
Panics
Panics if the required capacity exceeds the available capacity.
Returns the number of elements in the vector, also referred to as its length
.
Copies and appends all elements in a slice to the ScratchVec
.
The elements of the slice are appended in-order.
Removes the last element from a vector and returns it, or None
if it is empty.
Reserves the minimum capacity for exactly additional
more elements to be inserted in the
given AlignedVec
. After calling reserve_exact
, capacity will be greater than or equal
to self.len() + additional
. Does nothing if the capacity is already sufficient.
Panics
Panics if the required capacity exceeds the available capacity.
Forces the length of the vector to new_len
.
This is a low-level operation that maintains none of the normal invariants of the type.
Safety
new_len
must be less than or equal tocapacity()
- The elements at
old_len..new_len
must be initialized
Creates a draining iterator that removes the specified range in the vector and yields the removed items.
When the iterator is dropped, all elements in the range are removed from the vector,
even if the iterator was not fully consumed. If the iterator is not dropped (with
mem::forget
for example), it is unspecified how many elements are removed.
Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.
Assuming that all the elements are initialized, removes the MaybeUninit
wrapper from the
vector.
Safety
It is up to the caller to guarantee that the MaybeUninit<T>
elements really are in an
initialized state. Calling this when the content is not yet fully initialized causes
undefined behavior.
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for ScratchVec<T> where
T: RefUnwindSafe,
impl<T> !Send for ScratchVec<T>
impl<T> !Sync for ScratchVec<T>
impl<T> Unpin for ScratchVec<T>
impl<T> UnwindSafe for ScratchVec<T> where
T: RefUnwindSafe,
Blanket Implementations
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
Mutably borrows from an owned value. Read more