Crate dataview

source ·
Expand description

The Pod trait marks types whose values can be safely transmuted between byte arrays of the same size.

The DataView type defines read and write data APIs to an underlying byte buffer.

Examples

#[derive(dataview::Pod)]
#[repr(C)]
struct MyType {
	field: i32,
}

// Construct a zero initialized instance
let mut inst: MyType = dataview::zeroed();
assert_eq!(inst.field, 0);

// Use DataView to access the instance
let view = dataview::DataView::from_mut(&mut inst);
view.write(2, &255_u8);

// Create a byte view over the instance
assert_eq!(dataview::bytes(&inst), &[0, 0, 255, 0]);

Macros

Returns the offset of a field.
Returns the start..end offsets of a field.

Structs

Read and write data to and from the underlying byte buffer.

Traits

Types whose values can be safely transmuted between byte arrays of the same size.
Helper trait to provide methods directly on the pod types.

Functions

Returns the object’s memory as a byte slice.
Returns the object’s memory as a mutable byte slice.
Returns a zero-initialized instance of the type.

Derive Macros

Derive macro for the Pod trait.