pub struct Op<S: Span> { /* private fields */ }
Expand description
An operator. These can be parsed from tokens, and can also be used as parsers to parse one specific operator.
Implementations§
source§impl<S: Span> Op<S>
impl<S: Span> Op<S>
sourcepub fn new(str: impl Into<Cow<'static, str>>) -> Self
pub fn new(str: impl Into<Cow<'static, str>>) -> Self
Create a new operator. str
can’t be empty.
sourcepub const fn new_static(str: &'static str) -> Self
pub const fn new_static(str: &'static str) -> Self
Create a new operator (const). str
can’t be empty.
sourcepub fn with_span(str: impl Into<Cow<'static, str>>, span: S) -> Self
pub fn with_span(str: impl Into<Cow<'static, str>>, span: S) -> Self
Create a new operator with one specific span used for the whole operator.
str
can’t be empty.
sourcepub fn with_spans(str: impl Into<Cow<'static, str>>, spans: Vec<S>) -> Self
pub fn with_spans(str: impl Into<Cow<'static, str>>, spans: Vec<S>) -> Self
Create a new operator with a specific span for each character of the op.
The length of spans
must be the same as the number of characters in str
.
str
can’t be empty.
sourcepub fn puncts(&self) -> Puncts<'_, S::Punct> ⓘ
pub fn puncts(&self) -> Puncts<'_, S::Punct> ⓘ
Get an iterator over the Punct
s that make up this op.
sourcepub fn spans(&self) -> Option<&[S]>
pub fn spans(&self) -> Option<&[S]>
Get the spans of this op, or None
if the default span is used.
sourcepub fn set_spans(&mut self, spans: &[S])
pub fn set_spans(&mut self, spans: &[S])
Set the spans of this op. The lengths of spans
must be the same as the number of
characters in the string representation of this op.
Trait Implementations§
source§impl<S: SpanExt> IntoIterator for Op<S>
impl<S: SpanExt> IntoIterator for Op<S>
source§impl<T: TokenTreeExt> IntoTokens<T> for Op<T::Span>
impl<T: TokenTreeExt> IntoTokens<T> for Op<T::Span>
source§fn into_tokens(self) -> impl Iterator<Item = T>
fn into_tokens(self) -> impl Iterator<Item = T>
Convert this object into an iterator of tokens representing the object.
source§impl<S: SpanExt> Parse<<S as ProcMacro>::TokenTree> for Op<S>
impl<S: SpanExt> Parse<<S as ProcMacro>::TokenTree> for Op<S>
source§impl<T: TokenTreeExt> Parser<T> for Op<T::Span>
impl<T: TokenTreeExt> Parser<T> for Op<T::Span>
source§fn parse<'p, 'b>(
&'p self,
buf: &mut &'b TokenBuf<T>
) -> Result<Self::Output<'p, 'b>, Error<T::Span>>
fn parse<'p, 'b>( &'p self, buf: &mut &'b TokenBuf<T> ) -> Result<Self::Output<'p, 'b>, Error<T::Span>>
Parse a value from a
TokenBuf
using this parser. Read moresource§impl<S: SpanExt> ToTokenStream<<S as ProcMacro>::TokenStream> for Op<S>
impl<S: SpanExt> ToTokenStream<<S as ProcMacro>::TokenStream> for Op<S>
source§fn extend_token_stream(&self, token_stream: &mut S::TokenStream)
fn extend_token_stream(&self, token_stream: &mut S::TokenStream)
Extend the given
TokenStream
with a representation of this object.source§fn into_token_stream(self) -> Twhere
Self: Sized,
fn into_token_stream(self) -> Twhere
Self: Sized,
Make a new
TokenStream
with a representation of this object.source§fn to_token_stream(&self) -> T
fn to_token_stream(&self) -> T
Make a new
TokenStream
with a representation of this object.Auto Trait Implementations§
impl<S> Freeze for Op<S>
impl<S> RefUnwindSafe for Op<S>where
S: RefUnwindSafe,
impl<S> Send for Op<S>where
S: Send,
impl<S> Sync for Op<S>where
S: Sync,
impl<S> Unpin for Op<S>
impl<S> UnwindSafe for Op<S>where
S: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T, X> DefaultParser<T> for Xwhere
T: TokenTreeExt,
X: Parse<T>,
impl<T, X> DefaultParser<T> for Xwhere
T: TokenTreeExt,
X: Parse<T>,
source§impl<T, X> ToTokenBuffer<T> for X
impl<T, X> ToTokenBuffer<T> for X
source§fn extend_token_buffer(&self, token_buffer: &mut TokenBuffer<T>)
fn extend_token_buffer(&self, token_buffer: &mut TokenBuffer<T>)
Extend the given
TokenBuffer
with tokens representing this object.source§fn to_token_buffer(&self) -> TokenBuffer<T>
fn to_token_buffer(&self) -> TokenBuffer<T>
Make a new
TokenBuffer
with tokens representing this object.