Struct

core::cursor::Cursor

source
forall 'k.
exposed struct Cursor {
    view: Str['k],
    pos: usize,
}

A position in text, for reading it from front to back.

Methods

method newsource

fn new(view: Str['k]) -> Cursor['k] { ... }

A cursor at the start of view.

method possource

fn pos(self) -> usize { ... }

How far into view this cursor is.

method remainingsource

fn remaining(self) -> usize { ... }

Bytes left to read; 0 rather than a wrapped value if pos is past the end.

method at_endsource

fn at_end(self) -> bool { ... }

Whether no bytes are left to read.

method marksource

fn mark(self) -> usize { ... }

A checkpoint to measure from later: pos itself; see text_since.

method text_sincesource

fn text_since(self, mark: usize) -> Option[Str['k]] { ... }

The text from a previous mark() up to the current position; None if mark is after it or the range is out of bounds.

method peeksource

forall C where ReadBytes[C, Str['k]].
fn peek(self, &cx: C) -> Option[u8] { ... }

The byte at the current position, without advancing.

method peek_atsource

forall C where ReadBytes[C, Str['k]].
fn peek_at(self, &cx: C, offset: usize) -> Option[u8] { ... }

The byte offset positions ahead of the current one, without advancing; None past the end, however large offset is.

method nextsource

forall C where ReadBytes[C, Str['k]].
fn next(&self, &cx: C) -> Option[u8] { ... }

Reads the current byte and advances past it; None, cursor unchanged, at end of input.

method starts_withsource

forall C where ReadBytes[C, Str['k]].
fn starts_with(self, &cx: C, lit: Str['static]) -> bool { ... }

Whether the remaining input starts with lit's bytes, without advancing; false when fewer than lit.len() bytes remain.

method skip_whilesource

forall C where ReadBytes[C, Str['k]].
fn skip_while(self, &cx: C, pred: fn(u8) -> bool) -> Cursor['k] { ... }

The cursor advanced past every byte, from here on, that satisfies pred; unchanged if the current byte does not or input has ended.

method take_whilesource

forall C where ReadBytes[C, Str['k]].
fn take_while(&self, &cx: C, pred: fn(u8) -> bool) -> Str['k] { ... }

The text of every byte, from here on, that satisfies pred; advances the cursor past it.

method stepsource

forall C where ReadBytes[C, Str['k]].
fn step(self, &cx: C) -> (Cursor['k], Option[u8]) { ... }

The cursor advanced past the current byte, with that byte.

next returning the cursor, for &-sugar: let stepped = cur.step(&cx);.

method take_matchingsource

forall C where ReadBytes[C, Str['k]].
fn take_matching(self, &cx: C, pred: fn(u8) -> bool) -> (Cursor['k], Str['k]) { ... }

The cursor advanced past every byte that satisfies pred, with those bytes.

take_while shaped for &-sugar: let taken = cur.take_matching(&cx, is_digit);.

method take_exactsource

fn take_exact(self, count: usize) -> Option[(Cursor['k], Str['k])] { ... }

Exactly count bytes from here and the cursor advanced past them; None if fewer than count remain. Str::sub checks the range, so no capability is needed.

method remaining_viewsource

fn remaining_view(self) -> Str['k] { ... }

The whole remaining input as one text, without advancing.