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 true if the vector contains no elements.

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.

Appends an element to the back of a collection.

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 to capacity()
  • 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

Performs the conversion.

Performs the conversion.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Executes the destructor for this type. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

The archived version of the pointer metadata for this type.

Converts some archived metadata to the pointer metadata for itself.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Deserializes using the given deserializer

Performs the conversion.

Performs the conversion.

Gets the layout of the type.

The type for metadata in pointers and references to Self.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.