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(vec![0; 3]);

view.write_slice([4, 2]);
assert_eq!(view.offset, 2);
Panics

This function may panic, if the data is slice &mut [u8], and has not enough capacity.

But If the data is vector Vec<u8>, then it may reserve extra capacity if necessary.

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, ErrorKind};
let mut view = Cursor::new([1, 2, 3].as_ref());

let slice: Result<_, ()> = view.read_slice(2);
assert_eq!(slice, Ok([1, 2].as_ref()));
 
let slice: Result<_, ErrorKind> = view.read_slice(3);
assert_eq!(slice, Err(ErrorKind::InsufficientBytes));

Trait Implementations

Formats the value using the given formatter. Read more

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

Converts to this type from the input type.

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

Converts to this type from the input type.

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.