[][src]Struct flatdata::StructBuf

pub struct StructBuf<T> where
    T: for<'a> Struct<'a>, 
{ /* 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

use flatdata::StructBuf;

define_struct!(
    A,
    RefA,
    RefMutA,
    "no_schema",
    4,
    (x, set_x, u32, 0, 16),
    (y, set_y, u32, 16, 16)
);

let mut a = StructBuf::<A>::new();
a.get_mut().set_x(1);
a.get_mut().set_y(2);
assert_eq!(a.get().x(), 1);
assert_eq!(a.get().y(), 2);

Methods

impl<T> StructBuf<T> where
    T: for<'a> Struct<'a>, 
[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> Default for StructBuf<T> where
    T: for<'a> Struct<'a>, 
[src]

impl<T> AsRef<[u8]> for StructBuf<T> where
    T: for<'a> Struct<'a>, 
[src]

impl<T> Debug for StructBuf<T> where
    T: for<'a> Struct<'a>, 
[src]

Auto Trait Implementations

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

impl<T> Sync for StructBuf<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, 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]