planus::vectors

Struct Vector

Source
pub struct Vector<'buf, T: ?Sized> { /* private fields */ }
Expand description

A slice-like view into a serialized flatbuffer that deserializes on demand.

Implementations§

Source§

impl<'buf, T: ?Sized> Vector<'buf, T>

Source

pub const fn new_empty() -> Vector<'buf, T>

Returns an empty Vector

This is typically not very useful, since the vector is read-only, but has uses for instance as a default value.

Source

pub fn is_empty(self) -> bool

Checks if the vector is empty.

Source

pub fn len(self) -> usize

Returns the number of elements in the vector.

Source§

impl<'buf, T: VectorRead<'buf>> Vector<'buf, T>

Source

pub fn first(self) -> Option<T>

Returns the first element of the Vector, or None if it is empty.

Source

pub fn last(self) -> Option<T>

Returns the last element of the Vector, or None if it is empty.

Source

pub fn get<I>(self, index: I) -> Option<I::Output>
where I: VectorIndex<'buf, T>,

Returns an element or sub-vector depending on the type of index.

  • If given a position, returns the element at that position or None if out of bounds.
  • If given a range, returns the sub-vector corresponding to that range, or None if out of bounds.
Source

pub unsafe fn get_unchecked<I>(self, index: I) -> I::Output
where I: VectorIndex<'buf, T>,

Returns an element or sub-vector, without doing bounds checking.

For a safe alternative see get.

§Safety

Calling this method with an out-of-bounds index is undefined behavior even if the resulting output is not used.

Source

pub fn iter(self) -> Iter<'buf, T>

Returns an iterator over the vector.

Source

pub fn chunks(self, chunk_size: usize) -> Chunks<'buf, T>

Returns an iterator over chunk_size elements of the Vector at a time, starting at the beginning of the vector.

The chunks are Vectors themselves and do not overlap. If chunk_size does not divide the length of the Vector, then the last chunk will not have length chunk_size.

See chunks_exact for a variant of this iterator that returns chunks of always exactly chunk_size elements, and rchunks for the same iterator but starting at the end of the vector.

§Panics

Panics if chunk_size is 0.

Source

pub fn rchunks(self, chunk_size: usize) -> RChunks<'buf, T>

Returns an iterator over chunk_size elements of the Vector at a time, starting at the end of the vector.

The chunks are Vectors themselves and do not overlap. If chunk_size does not divide the length of the Vector, then the last chunk will not have length chunk_size.

See rchunks_exact for a variant of this iterator that returns chunks of always exactly chunk_size elements, and chunks for the same iterator but starting at the beginning of the vector.

§Panics

Panics if chunk_size is 0.

Source

pub fn chunks_exact(self, chunk_size: usize) -> ChunksExact<'buf, T>

Returns an iterator over chunk_size elements of the Vector at a time, starting at the beginning of the vector.

The chunks are Vectors themselves and do not overlap. If chunk_size does not divide the length of the vector, then the last up to chunk_size-1 elements will be omitted and can be retrieved from the remainder function of the iterator.

Due to each chunk having exactly chunk_size elements, the compiler can often optimize the resulting code better than in the case of chunks.

See chunks for a variant of this iterator that also returns the remainder as a smaller chunk, and rchunks_exact for the same iterator but starting at the end of the vector.

§Panics

Panics if chunk_size is 0.

Source

pub fn rchunks_exact(self, chunk_size: usize) -> RChunksExact<'buf, T>

Returns an iterator over chunk_size elements of the Vector at a time, starting at the end of the vector.

The chunks are Vectors themselves and do not overlap. If chunk_size does not divide the length of the vector, then the last up to chunk_size-1 elements will be omitted and can be retrieved from the remainder function of the iterator.

Due to each chunk having exactly chunk_size elements, the compiler can often optimize the resulting code better than in the case of rchunks.

See rchunks for a variant of this iterator that also returns the remainder as a smaller chunk, and chunks_exact for the same iterator but starting at the beginning of the vector.

§Panics

Panics if chunk_size is 0.

Source

pub fn windows(self, size: usize) -> Windows<'buf, T>

Returns an iterator over all contiguous windows of length size. The windows overlap. If the vector is shorter than size, the iterator returns no values.

§Panics

Panics if size is 0.

Source

pub fn split_first(self) -> Option<(T, Vector<'buf, T>)>

Returns the first and all the rest of the elements of the Vector, or None if it is empty

Source

pub fn split_last(self) -> Option<(T, Vector<'buf, T>)>

Returns the last and all the rest of the elements of the Vector, or None if it is empty

Source

pub fn split_at(self, mid: usize) -> Option<(Vector<'buf, T>, Vector<'buf, T>)>

Divides one Vector into two at an index.

The first will contain all indices from [0, mid) (excluding the index mid itself) and the second will contain all indices from [mid, len) (excluding the index len itself).

Source

pub unsafe fn split_at_unchecked( self, mid: usize, ) -> (Vector<'buf, T>, Vector<'buf, T>)

Divides one Vector into two at an index, without doing bounds checking.

The first will contain all indices from [0, mid) (excluding the index mid itself) and the second will contain all indices from [mid, len) (excluding the index len itself).

For a safe alternative see split_at.

§Safety

Calling this method with an out-of-bounds index is undefined behavior even if the resulting output is not used. The caller has to ensure that 0 <= mid <= self.len().

Source§

impl<'buf, T: VectorRead<'buf>> Vector<'buf, T>

Source

pub fn to_vec<O>(self) -> Result<Vec<O>>
where O: TryFrom<T>, Error: From<O::Error>,

Copies self into a new Vec.

Source§

impl<'buf, T, E> Vector<'buf, Result<T, E>>

Source

pub fn to_vec_result<O>(self) -> Result<Vec<O>>
where T: VectorReadInner<'buf>, E: From<T::Error>, O: TryFrom<T>, Error: From<E> + From<O::Error>,

Copies self into a new Vec.

Trait Implementations§

Source§

impl<'buf, T: ?Sized> Clone for Vector<'buf, T>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'buf, T> Debug for Vector<'buf, T>
where T: Debug + VectorRead<'buf>,

Source§

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

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

impl<'buf, T: VectorRead<'buf>> IntoIterator for Vector<'buf, T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'buf, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'buf, T: VectorRead<'buf>, O> TryFrom<Vector<'buf, T>> for Vec<O>
where O: TryFrom<T>, Error: From<O::Error>,

Source§

type Error = Error

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

fn try_from(value: Vector<'buf, T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'buf, T: ?Sized> Copy for Vector<'buf, T>

Auto Trait Implementations§

§

impl<'buf, T> Freeze for Vector<'buf, T>
where T: ?Sized,

§

impl<'buf, T> RefUnwindSafe for Vector<'buf, T>
where T: RefUnwindSafe + ?Sized,

§

impl<'buf, T> Send for Vector<'buf, T>
where T: Sync + ?Sized,

§

impl<'buf, T> Sync for Vector<'buf, T>
where T: Sync + ?Sized,

§

impl<'buf, T> Unpin for Vector<'buf, T>
where T: ?Sized,

§

impl<'buf, T> UnwindSafe for Vector<'buf, T>
where T: RefUnwindSafe + ?Sized,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.