pub trait View {
    fn read_at<E>(&self, offset: usize) -> E
    where
        E: Endian,
        [(); E::NBYTES]:
;
fn write_at<E>(&mut self, value: E, offset: usize)
    where
        E: Endian,
        [u8; E::NBYTES]:
; }
Expand description

A data view for reading and writing data in a byte array.

Examples

use data_view::View;

let mut buf = [0; 16];

buf.write_at(42_u16, 1);
assert_eq!(buf.read_at::<u16>(1), 42);

Panics

Panics if the offset is out of bounds.

Required methods

Reads a value of type E from the data view. where E implements Endian.

Examples
use data_view::View;

let mut buf: [u8; 2] = [12, 34];

assert_eq!(buf.read_at::<u8>(0), 12);
assert_eq!(buf.read_at::<u8>(1), 34);
Panics

Panics if the offset is out of bounds.

Writes a value of type E to the data view. where E is a type that implements Endian.

Examples
use data_view::View;

let mut buf: [u8; 2] = [0; 2];

buf.write_at(12_u8, 0);
buf.write_at(34_u8, 1);
assert_eq!(buf, [12, 34]);
Panics

Panics if the offset is out of bounds.

Implementations on Foreign Types

Implementors