pub struct Cursor<'a> { /* private fields */ }Expand description
A sequential reader over a borrowed slice. It advances only after a successful read or seek, so a refused read leaves it where it was.
Implementations§
Source§impl<'a> Cursor<'a>
impl<'a> Cursor<'a>
Sourcepub fn new(data: &'a [u8]) -> Self
pub fn new(data: &'a [u8]) -> Self
A cursor at the start of data, whose first byte is offset 0 of the file.
Sourcepub fn with_origin(data: &'a [u8], origin: usize) -> Self
pub fn with_origin(data: &'a [u8], origin: usize) -> Self
A cursor at the start of data, whose first byte is offset origin of the file.
Sourcepub fn bytes(&self) -> &'a [u8] ⓘ
pub fn bytes(&self) -> &'a [u8] ⓘ
All the bytes it reads, from its start (a parser that looks back or ahead by offset).
Sourcepub fn take_to(&mut self, end: usize) -> Result<&'a [u8], BoundsError>
pub fn take_to(&mut self, end: usize) -> Result<&'a [u8], BoundsError>
The bytes from the position up to end (an offset in the view), the cursor left at end: refused when end
is before the position or past the view.
Sourcepub fn seek(&mut self, offset: usize) -> Result<(), BoundsError>
pub fn seek(&mut self, offset: usize) -> Result<(), BoundsError>
Moves to offset (the end of the data is allowed); an offset past it is refused.
Sourcepub fn u8(&mut self) -> Result<u8, BoundsError>
pub fn u8(&mut self) -> Result<u8, BoundsError>
The next byte.
Sourcepub fn i8(&mut self) -> Result<i8, BoundsError>
pub fn i8(&mut self) -> Result<i8, BoundsError>
The next byte, signed.
Sourcepub fn count(&mut self, e: Endian, each: usize) -> Result<usize, BoundsError>
pub fn count(&mut self, e: Endian, each: usize) -> Result<usize, BoundsError>
A u32 count, in byte order e, of records of each bytes that the rest of the view holds; a count it
can’t hold is refused, its span’s error naming where the records would start, and the cursor stays before the
count. A zero each bounds nothing (checked_span).