pub struct Cursor<'a> { /* private fields */ }Expand description
An immutable cursor into a list of tokens.
This cursor cannot be mutated but can be used to parse more tokens in a list
of tokens. Cursors are created from the Parser::step method. This is a
very low-level parsing structure and you likely won’t use it much.
Implementations
sourceimpl<'a> Cursor<'a>
 
impl<'a> Cursor<'a>
sourcepub fn cur_span(&self) -> Span
 
pub fn cur_span(&self) -> Span
Returns the span of the next Token token.
Does not take into account whitespace or comments.
sourcepub fn error(&self, msg: impl Display) -> Error
 
pub fn error(&self, msg: impl Display) -> Error
Same as Parser::error, but works with the current token in this
Cursor instead.
sourcepub fn lparen(self) -> Option<Self>
 
pub fn lparen(self) -> Option<Self>
Attempts to advance this cursor if the current token is a (.
If the current token is (, returns a new Cursor pointing at the
rest of the tokens in the stream. Otherwise returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn rparen(self) -> Option<Self>
 
pub fn rparen(self) -> Option<Self>
Attempts to advance this cursor if the current token is a ).
If the current token is ), returns a new Cursor pointing at the
rest of the tokens in the stream. Otherwise returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn id(self) -> Option<(&'a str, Self)>
 
pub fn id(self) -> Option<(&'a str, Self)>
Attempts to advance this cursor if the current token is a
Token::Id
If the current token is Id, returns the identifier minus the leading
$ character as well as a new Cursor pointing at the rest of the
tokens in the stream. Otherwise returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn keyword(self) -> Option<(&'a str, Self)>
 
pub fn keyword(self) -> Option<(&'a str, Self)>
Attempts to advance this cursor if the current token is a
Token::Keyword
If the current token is Keyword, returns the keyword as well as a new
Cursor pointing at the rest of the tokens in the stream. Otherwise
returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn reserved(self) -> Option<(&'a str, Self)>
 
pub fn reserved(self) -> Option<(&'a str, Self)>
Attempts to advance this cursor if the current token is a
Token::Reserved
If the current token is Reserved, returns the reserved token as well
as a new Cursor pointing at the rest of the tokens in the stream.
Otherwise returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn integer(self) -> Option<(&'a Integer<'a>, Self)>
 
pub fn integer(self) -> Option<(&'a Integer<'a>, Self)>
Attempts to advance this cursor if the current token is a
Token::Integer
If the current token is Integer, returns the integer as well as a new
Cursor pointing at the rest of the tokens in the stream. Otherwise
returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn float(self) -> Option<(&'a Float<'a>, Self)>
 
pub fn float(self) -> Option<(&'a Float<'a>, Self)>
Attempts to advance this cursor if the current token is a
Token::Float
If the current token is Float, returns the float as well as a new
Cursor pointing at the rest of the tokens in the stream. Otherwise
returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn string(self) -> Option<(&'a [u8], Self)>
 
pub fn string(self) -> Option<(&'a [u8], Self)>
Attempts to advance this cursor if the current token is a
Token::String
If the current token is String, returns the byte value of the string
as well as a new Cursor pointing at the rest of the tokens in the
stream. Otherwise returns None.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn annotation(self) -> Option<(&'a str, Self)>
 
pub fn annotation(self) -> Option<(&'a str, Self)>
Attempts to advance this cursor if the current token is a
Token::Reserved and looks like the start of an
annotation.
Annotations are a WebAssembly proposal for the text format which allows placing structured text inside of a text file, for example to specify the name section or other custom sections.
This function will attempt to see if the current token is the @foo
part of the annotation. This requires the previous token to be ( and
the current token is Reserved which starts with @ and has a nonzero
length for the following name.
Note that this will skip unknown annoations. Only pre-registered annotations will be returned here.
This function will automatically skip over any comments, whitespace, or unknown annotations.
sourcepub fn comment(self) -> Option<(&'a str, Self)>
 
pub fn comment(self) -> Option<(&'a str, Self)>
Attempts to advance this cursor if the current token is a
Token::LineComment or a
Token::BlockComment
This function will only skip whitespace, no other tokens.
Trait Implementations
Auto Trait Implementations
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> !UnwindSafe for Cursor<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
    T: ?Sized, 
 
impl<T> BorrowMut<T> for T where
    T: ?Sized, 
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
 
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
    T: Clone, 
 
impl<T> ToOwned for T where
    T: Clone, 
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
 
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
 
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more