[][src]Struct flatdata::Vector

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,
    RefA,
    RefMutA,
    "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: for<'b> Struct<'b>, 
[src]

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) -> <T as Struct>::ItemMut
[src]

Appends an element to the end of this vector and returns a mutable handle to it.

pub fn at(&self, index: usize) -> <T as Struct>::Item
[src]

Return an accessor handle to the element at position index in the vector.

pub fn at_mut(&mut self, index: usize) -> <T as Struct>::ItemMut
[src]

Return a mutable handle to the element at position index in the vector.

Trait Implementations

impl<T> Default for Vector<T> where
    T: for<'b> Struct<'b>, 
[src]

fn default() -> Self
[src]

Creates an empty Vector<T>.

impl<T> AsRef<[u8]> for Vector<T> where
    T: for<'b> Struct<'b>, 
[src]

fn as_ref(&self) -> &[u8]
[src]

Returns the content of this vector as slice of bytes. Equivalent to as_bytes.

impl<T: Clone> Clone for Vector<T>
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T> Debug for Vector<T> where
    T: for<'b> Struct<'b>, 
[src]

Auto Trait Implementations

impl<T> Send for Vector<T> where
    T: Send

impl<T> Sync for Vector<T> where
    T: Sync

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]