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]

Creates an empty Vector<T>.

Creates a Vector<T> with len many elements.

T's fields are all filled with zeroes.

Size of the vector in bytes.

Number of elements in the vector.

Returns true if the vector has a length 0.

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.

Returns an ArrayView to this vector.

Returns the contents of this vector as slice of bytes.

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

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

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

Trait Implementations

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Struct> Default for Vector<T>
[src]

Creates an empty Vector<T>.

impl<T: Struct> AsRef<[u8]> for Vector<T>
[src]

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

impl<T: Struct> Debug for Vector<T>
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

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

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