Struct flatdata::ExternalVector [−][src]
pub struct ExternalVector<T> { /* fields omitted */ }
Vector which flushes its content when growing.
Useful for serialization of data which does not fully fit in memory.
External vector does not provide access to elements previously added to it.
Only the last element added to the vector using the result of the method
grow
can be accessed and written.
An external vector must be closed, after the last element was written to it. After closing, it can not be used anymore. Not closing the vector will result in panic on drop (in debug mode).
Examples
use flatdata::{ create_external_vector, ArrayView, ExternalVector, MemoryResourceStorage, ResourceStorage, }; define_struct!(A, AMut, "no_schema", 4, (x, set_x, u32, 0, 16), (y, set_y, u32, 16, 16) ); let mut storage = MemoryResourceStorage::new("/root/extvec".into()); { let mut v = create_external_vector::<A>( &mut storage, "vector", "Some schema content") .expect("failed to create ExternalVector"); { let mut a = v.grow().expect("grow failed"); a.set_x(0); a.set_y(1); } { let mut a = v.grow().expect("grow failed"); a.set_x(2); a.set_y(3); } v.close().expect("close failed"); } let resource = storage .read_and_check_schema("vector", "Some schema content") .expect("failed to read vector resource"); let view: ArrayView<A> = ArrayView::new(&resource); assert_eq!(view.len(), 2); assert_eq!(view.at(0).x(), 0); assert_eq!(view.at(0).y(), 1); assert_eq!(view.at(1).x(), 2); assert_eq!(view.at(1).y(), 3);
Methods
impl<T: Struct> ExternalVector<T>
[src]
impl<T: Struct> ExternalVector<T>
pub fn new(resource_handle: ResourceHandle) -> Self
[src]
pub fn new(resource_handle: ResourceHandle) -> Self
Creates an empty ExternalVector<T>
in the given resource storage.
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Number of elements that where added to this vector.
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Returns true
if no element were added to this vector yet.
pub fn grow(&mut self) -> Result<HandleMut<T::Mut>>
[src]
pub fn grow(&mut self) -> Result<HandleMut<T::Mut>>
Appends an element to the end of this vector and returns a mutable handle to it.
Calling this method may flush data to storage (cf. flush
), which
may fail due to different IO reasons.
pub fn is_open(&self) -> bool
[src]
pub fn is_open(&self) -> bool
Returns true
if this vector was not closed yet and more elements can
be added to it.
pub fn close(&mut self) -> Result<()>
[src]
pub fn close(&mut self) -> Result<()>
Flushes the remaining not yet flushed elements in this vector and finalizes the data inside the storage.
After this method is called, more data cannot be written into this vector. An external vector must be closed, otherwise it will panic on drop (in debug mode).
Trait Implementations
impl<T> Drop for ExternalVector<T>
[src]
impl<T> Drop for ExternalVector<T>
impl<T: Struct> Debug for ExternalVector<T>
[src]
impl<T: Struct> Debug for ExternalVector<T>
Auto Trait Implementations
impl<T> !Send for ExternalVector<T>
impl<T> !Send for ExternalVector<T>
impl<T> !Sync for ExternalVector<T>
impl<T> !Sync for ExternalVector<T>