Skip to main content

Cursor

Struct Cursor 

Source
pub struct Cursor { /* private fields */ }
Expand description

A raw-pointer scan cursor over a NUL-terminated source buffer.

Implementations§

Source§

impl Cursor

Source

pub fn new(buffer: Rc<SourceBuffer>) -> Cursor

Create a cursor positioned at the start of buffer.

Source

pub fn offset(&self) -> u32

The current byte offset from the start of the buffer.

Source

pub fn at_end(&self) -> bool

True once the cursor has reached the terminating NUL.

Source

pub fn peek(&self) -> u8

Byte at the cursor (or the NUL terminator at end).

Source

pub fn peek_at(&self, n: usize) -> u8

Byte n ahead of the cursor. Only valid while the bytes in between were non-NUL (the C++ lookahead invariant); reading the terminating NUL is always in-bounds.

Source

pub fn advance(&mut self, n: usize)

Advance the cursor by n bytes.

Source

pub fn seek(&mut self, offset: u32)

Seek to an absolute byte offset.

Source

pub fn seek_end(&mut self)

Move the cursor to EOF (the terminating NUL). Port of forceEOF.

Source

pub fn slice_from(&self, from_offset: u32) -> &[u8]

Bytes in [from_offset, current offset).

Source

pub fn slice(&self, from_offset: u32, to_offset: u32) -> &[u8]

Bytes in [from_offset, to_offset).

Source

pub fn raw(&self) -> &[u8]

The NUL-terminated raw bytes of the underlying buffer.

Source

pub fn peek_utf8(&self) -> (u32, u32)

Decode the (non-ASCII) UTF-8 char at the cursor WITHOUT advancing. Port of JSLexer::_peekUTF8 (JSLexer.h:1159-1167): it decodes with surrogates disallowed and swallows any errors. Returns (code_point, offset_after), where offset_after is the byte offset of the next character.

This stays in cursor.rs to keep the raw-pointer parity confined here, but it actually drives the safe utf8::decode_utf8 over raw() at a copied byte offset (no new unsafe).

Source

pub fn buffer(&self) -> &Rc<SourceBuffer>

The underlying buffer (cloning the Rc is cheap).

Auto Trait Implementations§

§

impl !RefUnwindSafe for Cursor

§

impl !Send for Cursor

§

impl !Sync for Cursor

§

impl !UnwindSafe for Cursor

§

impl Freeze for Cursor

§

impl Unpin for Cursor

§

impl UnsafeUnpin for Cursor

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.