Struct flatdata::Vector
[−]
[src]
pub struct Vector<T> { /* fields omitted */ }
A container holding a contiguous sequence of flatdata structs of the same
type T
in memory, and providing read and write access to it.
Vector data is fully stored and populated in memory before it is
serialized. This container is often used for data which needs to be changed
or updated after insertion in the container. When data can be incrementally
serialized without later updates, ExternalVector
is usually a
better choice since it may decrease the memory footprint of serialization
significantly.
An archive builder provides a setter for each vector resource. Use
as_view
and the corresponding setter to write a Vector
to storage.
Examples
use flatdata::Vector; define_struct!(A, AMut, "no_schema", 4, (x, set_x, u32, 0, 16), (y, set_y, u32, 16, 16) ); let mut v: Vector<A> = Vector::new(); { let mut a = v.grow(); a.set_x(1); a.set_y(2); } { let mut b = v.grow(); b.set_x(3); b.set_y(4); } assert_eq!(v.len(), 2); // serialize // SomeArchiveBuilder.set_vector_resource_of_a_s(&v.as_view());
Methods
impl<T> Vector<T> where
T: Struct,
[src]
T: Struct,
pub fn new() -> Self
[src]
Creates an empty Vector<T>
.
pub fn with_len(len: usize) -> Self
[src]
Creates a Vector<T>
with len
many elements.
T
's fields are all filled with zeroes.
pub fn size_in_bytes(&self) -> usize
[src]
Size of the vector in bytes.
pub fn len(&self) -> usize
[src]
Number of elements in the vector.
pub fn is_empty(&self) -> bool
[src]
Returns true
if the vector has a length 0.
pub fn reserve(&mut self, additional: usize)
[src]
Reserves capacity for at least additional
more elements to be
inserted in the given vector. The collection may reserve more space
to avoid frequent reallocations. After calling reserve, capacity
will be greater than or equal to self.len() + additional
. Does nothing
if capacity is already sufficient.
pub fn as_view(&self) -> ArrayView<T>
[src]
Returns an ArrayView
to this vector.
pub fn as_bytes(&self) -> &[u8]
[src]
Returns the contents of this vector as slice of bytes.
pub fn grow(&mut self) -> HandleMut<T::Mut>
[src]
Appends an element to the end of this vector and returns a mutable handle to it.
pub fn at(&self, index: usize) -> Handle<T>
[src]
Return an accessor handle to the element at position index
in the
vector.
pub fn at_mut(&mut self, index: usize) -> HandleMut<T::Mut>
[src]
Return a mutable handle to the element at position index
in the
vector.
Trait Implementations
impl<T: Clone> Clone for Vector<T>
[src]
fn clone(&self) -> Vector<T>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<T: Struct> Default for Vector<T>
[src]
impl<T: Struct> AsRef<[u8]> for Vector<T>
[src]
fn as_ref(&self) -> &[u8]
[src]
Returns the content of this vector as slice of bytes. Equivalent to
as_bytes
.