Skip to main content

RawVec

Struct RawVec 

Source
pub struct RawVec { /* private fields */ }
Expand description

A vector of bytes aligned to a given value. The alignment can be increase by calling align.

Implementations§

Source§

impl RawVec

Source

pub fn with_base_alignment(base_alignment: usize) -> Self

Creates a new RawVec with base alignment.

§Examples
use cel_runtime::RawVec;
use std::mem::align_of;
let vec = RawVec::with_base_alignment(align_of::<u32>());
Source

pub fn with_base_alignment_and_capacity( base_alignment: usize, capacity: usize, ) -> Self

Creates a new RawVec with base alignment and initial capacity.

Source

pub fn capacity(&self) -> usize

Returns the capacity of the vector in bytes.

Source

pub fn len(&self) -> usize

Returns the current length of the vector in bytes.

Source

pub fn is_empty(&self) -> bool

Returns true if the vector contains no bytes.

Source

pub fn reserve(&mut self, addition: usize)

Reserves capacity for at least additional more elements. The collection may reserve more space to guarantee amortized constant time growth. After calling reserve, capacity will be greater than or equal to self.len() + additional. Does nothing if capacity is already sufficient.

§Panics

Panics if the new capacity exceeds isize::MAX bytes.

Source

pub unsafe fn set_len(&mut self, len: usize)

Sets the length of the vector.

§Panics
  • The length must be less than or equal to the capacity.
§Safety
  • The elements at old_len..new_len must be initialized.
Source

pub unsafe fn as_mut_ptr(&mut self) -> *mut MaybeUninit<u8>

Returns a raw mutable pointer to the vector’s buffer, or a dangling raw pointer valid for zero sized reads if the vector didn’t allocate.

This method guarantees that for the purpose of the aliasing model, this method does not materialize a reference to the underlying slice, and thus the returned pointer will remain valid when mixed with other calls to Self::as_ptr, Self::as_mut_ptr. Note that calling other methods that materialize references to the slice, or references to specific elements you are planning on accessing through this pointer, may still invalidate this pointer.

§Safety

The pointer is valid until the vector buffer is reallocated or the vector’s lifetime ends.

Source

pub unsafe fn as_ptr(&self) -> *const MaybeUninit<u8>

Returns a raw pointer to the vector’s buffer, or a dangling raw pointer valid for zero sized reads if the vector didn’t allocate.

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 Self::as_mut_ptr.

This method guarantees that for the purpose of the aliasing model, this method does not materialize a reference to the underlying slice, and thus the returned pointer will remain valid when mixed with other calls to Self::as_ptr, Self::as_mut_ptr. Note that calling other methods that materialize mutable references to the slice, or mutable references to specific elements you are planning on accessing through this pointer, as well as writing to those elements, may still invalidate this pointer.

§Safety

The pointer is valid until the vector buffer is reallocated or the vector’s lifetime ends.

Source

pub fn truncate(&mut self, len: usize)

Shortens the vector, keeping the first len elements and dropping the rest.

If len is greater or equal to the vector’s current length, this has no effect.

Trait Implementations§

Source§

impl Debug for RawVec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I> Index<I> for RawVec
where I: SliceIndex<[MaybeUninit<u8>]>,

Source§

type Output = <I as SliceIndex<[MaybeUninit<u8>]>>::Output

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

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

impl<I> IndexMut<I> for RawVec
where I: SliceIndex<[MaybeUninit<u8>]>,

Source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.