Struct proclet::Op

source ·
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>

source

pub fn new(str: impl Into<Cow<'static, str>>) -> Self

Create a new operator. str can’t be empty.

source

pub const fn new_static(str: &'static str) -> Self

Create a new operator (const). str can’t be empty.

source

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.

source

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.

source

pub fn as_str(&self) -> &str

Get this op as a string.

source

pub fn puncts(&self) -> Puncts<'_, S::Punct>

Get an iterator over the Puncts that make up this op.

source

pub fn spans(&self) -> Option<&[S]>

Get the spans of this op, or None if the default span is used.

source

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.

source

pub fn span(&self) -> Option<S>

Get the span of this op. If the op has more than one span, this will currently return the first span. This may change in the future if proc-macro* exposes the ability to merge spans.

source

pub fn set_span(&mut self, span: S)

Set a single span for this op.

source§

impl<S: SpanExt> Op<S>

source

pub fn split( &self, parser: &OpParser<S::Punct, impl MatchOpFn> ) -> ParseOps<S, Puncts<'_, S::Punct>, impl MatchOpFn>

Split this op using the provided OpParser.

Trait Implementations§

source§

impl<S: Clone + Span> Clone for Op<S>

source§

fn clone(&self) -> Op<S>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<S: Debug + Span> Debug for Op<S>

source§

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

Formats the value using the given formatter. Read more
source§

impl<S: Span> From<&'static str> for Op<S>

source§

fn from(value: &'static str) -> Self

Converts to this type from the input type.
source§

impl<S: SpanExt> IntoIterator for Op<S>

§

type Item = <S as ProcMacro>::Punct

The type of the elements being iterated over.
§

type IntoIter = Puncts<'static, <S as ProcMacro>::Punct>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T: TokenTreeExt> IntoTokens<T> for Op<T::Span>

source§

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>

source§

fn parse(buf: &mut &TokenBuf<S::TokenTree>) -> Result<Self, Error<S>>

Generic op parser. This doesn’t check against valid ops.

source§

fn parse_all(buf: &mut &TokenBuf<T>) -> Result<Self, Error<T::Span>>

Parse a value from a TokenBuf buffer, but return an error if there’s any tokens left in the buffer after parsing. Read more
source§

impl<T: TokenTreeExt> Parser<T> for Op<T::Span>

§

type Output<'p, 'b> = Op<<T as ProcMacro>::Span> where Self: 'p

The output type of this parser.
source§

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 more
source§

fn parse_all<'p, 'b>( &'p self, buf: &mut &'b TokenBuf<T> ) -> Result<Self::Output<'p, 'b>, Error<T::Span>>

Parse a value from a TokenBuf buffer, but return an error if there’s any tokens left in the buffer after parsing. Read more
source§

fn optional(self) -> Optional<Self>
where Self: Sized,

Wrap this parser in Optional to make it always succeed and return an option.
source§

impl<S: SpanExt> ToTokenStream<<S as ProcMacro>::TokenStream> for Op<S>

source§

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) -> T
where Self: Sized,

Make a new TokenStream with a representation of this object.
source§

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> 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, X> DefaultParser<T> for X
where T: TokenTreeExt, X: Parse<T>,

§

type Parser = DefaultParserImpl<T, X>

The parser that will be created.
source§

fn parser() -> Self::Parser

Create a new parser.
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> ToOwned for T
where T: Clone,

§

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, X> ToTokenBuffer<T> for X
where T: TokenTree, X: IntoTokens<T> + Clone,

source§

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>

Make a new TokenBuffer with tokens representing this object.
source§

impl<T, X> ToTokens<T> for X
where T: TokenTree, X: IntoTokens<T> + Clone,

source§

fn to_tokens(&self) -> impl Iterator<Item = T>

Get an iterator of tokens representing this object.
source§

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

§

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>,

§

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.