[][src]Struct flatdata::StructBuf

pub struct StructBuf<T> where
    T: RefFactory + NoOverlap
{ /* fields omitted */ }

A container holding a single flatdata struct in memory, and providing read and write access to it.

Used in combination with ArchiveBuilder to serialize single struct resources, cf. coappearances example.

A struct buffer derefs (const and mut) to a reference of the underlying struct, therefore, struct getters and setters can be used directly on buffer.

Examples

struct A {
    x : u32 : 16;
    y : u32 : 16;
}

archive X {
   data : A;
}
let storage = MemoryResourceStorage::new("/root/structbuf");
let builder = XBuilder::new(storage.clone()).expect("failed to create builder");
let mut a = StructBuf::<A>::new();
a.get_mut().set_x(1);
a.get_mut().set_y(2);
builder.set_data(a.get());

println!("{:?}", storage);
let archive = X::open(storage).expect("failed to open");
let view = archive.data();

assert_eq!(view.x(), 1);
assert_eq!(view.y(), 2);

Methods

impl<T> StructBuf<T> where
    T: RefFactory + NoOverlap
[src]

pub fn new() -> Self[src]

Creates an empty struct buffer.

All fields are set to 0.

pub fn get(&self) -> <T as Struct>::Item[src]

Get the stored object

pub fn get_mut(&mut self) -> <T as Struct>::ItemMut[src]

Get the mutable version of the stored object

pub fn as_bytes(&self) -> &[u8][src]

Returns a raw bytes representation of the buffer.

Trait Implementations

impl<T> AsRef<[u8]> for StructBuf<T> where
    T: RefFactory + NoOverlap
[src]

impl<T> Default for StructBuf<T> where
    T: RefFactory + NoOverlap
[src]

impl<T> Debug for StructBuf<T> where
    T: RefFactory + NoOverlap
[src]

Auto Trait Implementations

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

impl<T> Unpin for StructBuf<T> where
    T: Unpin

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

impl<T> UnwindSafe for StructBuf<T> where
    T: UnwindSafe

impl<T> RefUnwindSafe for StructBuf<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

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

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

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