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§

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

Structs§

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

Traits§

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

Functions§

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

Derive Macros§

Pod
Derive macro for the Pod trait.