Skip to main content

Cursor

Struct Cursor 

Source
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 Cursor<'_>

Source

pub fn u16(&mut self, e: Endian) -> Result<u16, BoundsError>

The next u16, in byte order e.

Source

pub fn i16(&mut self, e: Endian) -> Result<i16, BoundsError>

The next i16, in byte order e.

Source

pub fn u32(&mut self, e: Endian) -> Result<u32, BoundsError>

The next u32, in byte order e.

Source

pub fn i32(&mut self, e: Endian) -> Result<i32, BoundsError>

The next i32, in byte order e.

Source

pub fn u64(&mut self, e: Endian) -> Result<u64, BoundsError>

The next u64, in byte order e.

Source

pub fn i64(&mut self, e: Endian) -> Result<i64, BoundsError>

The next i64, in byte order e.

Source

pub fn f32(&mut self, e: Endian) -> Result<f32, BoundsError>

The next f32, in byte order e.

Source

pub fn f64(&mut self, e: Endian) -> Result<f64, BoundsError>

The next f64, in byte order e.

Source§

impl<'a> Cursor<'a>

Source

pub fn new(data: &'a [u8]) -> Self

A cursor at the start of data, whose first byte is offset 0 of the file.

Source

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.

Source

pub fn position(&self) -> usize

The offset of the next byte to read, within the cursor’s data.

Source

pub fn bytes(&self) -> &'a [u8] ⓘ

All the bytes it reads, from its start (a parser that looks back or ahead by offset).

Source

pub fn remaining(&self) -> usize

How many bytes are left after the position.

Source

pub fn take(&mut self, length: usize) -> Result<&'a [u8], BoundsError>

The next length bytes.

Source

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.

Source

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.

Source

pub fn array<const N: usize>(&mut self) -> Result<[u8; N], BoundsError>

The next N bytes.

Source

pub fn u8(&mut self) -> Result<u8, BoundsError>

The next byte.

Source

pub fn i8(&mut self) -> Result<i8, BoundsError>

The next byte, signed.

Source

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).

Trait Implementations§

Source§

impl<'a> Clone for Cursor<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Cursor<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Forget for Cursor<'a>

§

impl<'a> Freeze for Cursor<'a>

§

impl<'a> RefUnwindSafe for Cursor<'a>

§

impl<'a> Send for Cursor<'a>

§

impl<'a> Sync for Cursor<'a>

§

impl<'a> Unpin for Cursor<'a>

§

impl<'a> UnsafeUnpin for Cursor<'a>

§

impl<'a> UnwindSafe for Cursor<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.