[−][src]Struct flatdata::StructBuf
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]
T: RefFactory + NoOverlap,
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]
T: RefFactory + NoOverlap,
impl<T> Default for StructBuf<T> where
T: RefFactory + NoOverlap, [src]
T: RefFactory + NoOverlap,
impl<T> Debug for StructBuf<T> where
T: RefFactory + NoOverlap, [src]
T: RefFactory + NoOverlap,
Auto Trait Implementations
impl<T> Send for StructBuf<T> where
T: Send,
T: Send,
impl<T> Unpin for StructBuf<T> where
T: Unpin,
T: Unpin,
impl<T> Sync for StructBuf<T> where
T: Sync,
T: Sync,
impl<T> UnwindSafe for StructBuf<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for StructBuf<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,