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>
impl<'buf, T: ?Sized> Vector<'buf, T>
Source§impl<'buf, T: VectorRead<'buf>> Vector<'buf, T>
impl<'buf, T: VectorRead<'buf>> Vector<'buf, T>
Sourcepub fn first(self) -> Option<T>
pub fn first(self) -> Option<T>
Returns the first element of the Vector
, or None
if it is empty.
Sourcepub fn get<I>(self, index: I) -> Option<I::Output>where
I: VectorIndex<'buf, T>,
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.
Sourcepub unsafe fn get_unchecked<I>(self, index: I) -> I::Outputwhere
I: VectorIndex<'buf, T>,
pub unsafe fn get_unchecked<I>(self, index: I) -> I::Outputwhere
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.
Sourcepub fn chunks(self, chunk_size: usize) -> Chunks<'buf, T> ⓘ
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 Vector
s 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.
Sourcepub fn rchunks(self, chunk_size: usize) -> RChunks<'buf, T> ⓘ
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 Vector
s 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.
Sourcepub fn chunks_exact(self, chunk_size: usize) -> ChunksExact<'buf, T> ⓘ
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 Vector
s 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.
Sourcepub fn rchunks_exact(self, chunk_size: usize) -> RChunksExact<'buf, T> ⓘ
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 Vector
s 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.
Sourcepub fn windows(self, size: usize) -> Windows<'buf, T> ⓘ
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.
Sourcepub fn split_first(self) -> Option<(T, Vector<'buf, T>)>
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
Sourcepub fn split_last(self) -> Option<(T, Vector<'buf, T>)>
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
Sourcepub fn split_at(self, mid: usize) -> Option<(Vector<'buf, T>, Vector<'buf, T>)>
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).
Sourcepub unsafe fn split_at_unchecked(
self,
mid: usize,
) -> (Vector<'buf, T>, Vector<'buf, T>)
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()
.