pub struct Cursor<T> {
    pub data: T,
    pub offset: usize,
}

Fields

data: Toffset: usize

Implementations

Writes a slice into the data view.

Examples
use bin_layout::{Cursor, ErrorKind};

let mut view = Cursor::new([0; 3]);

assert_eq!(view.write_slice([4, 2]), Ok(()));
assert_eq!(view.write_slice([1, 2, 3]), Err(ErrorKind::InsufficientBytes));
 
assert_eq!(view.data, [4, 2, 0]);
assert_eq!(view.offset, 2);

Returns remaining slice from the current offset. It doesn’t change the offset.

Examples
use bin_layout::Cursor;

let mut view = Cursor::new([1, 2].as_ref());

assert_eq!(view.remaining_slice(), &[1, 2]);
view.offset = 42;
assert!(view.remaining_slice().is_empty());

Read slice from the current offset.

Example
use bin_layout::Cursor;
let mut view = Cursor::new([1, 2, 3].as_ref());

assert_eq!(view.read_slice(2), Ok([1, 2].as_ref()));
assert!(view.read_slice(3).is_err());

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.