TokenOutputTrimmer

Struct TokenOutputTrimmer 

Source
pub struct TokenOutputTrimmer<'t, 'o> {
    preamble: Option<&'t dyn ToTokens>,
    sep: &'t dyn ToTokens,
    sep_count: usize,
    out: &'o mut TokenStream,
}
Expand description

For making an output TokenStream, but eliding an unnecessary tail

This construction will write, to an output TokenStream,

  • preamble
  • zero or more optional impl ToTokens, called “reified”
  • interleaved with zero or more optional separators sep

But it will avoid writing trailing unnecessary content: that is, trailing calls to push_sep are ignored, and if push_reified is never called, the preamble is also omitted.

Fields§

§preamble: Option<&'t dyn ToTokens>§sep: &'t dyn ToTokens§sep_count: usize§out: &'o mut TokenStream

Implementations§

Source§

impl<'t, 'o> TokenOutputTrimmer<'t, 'o>

Source

pub fn new( out: &'o mut TokenStream, preamble: &'t dyn ToTokens, sep: &'t dyn ToTokens, ) -> Self

Source

pub fn push_sep(&mut self)

Source

fn reify(&mut self)

Source

pub fn push_reified(&mut self, t: impl ToTokens)

Source

pub fn did_preamble(self) -> Option<()>

Did we output the preamble at all?

Auto Trait Implementations§

§

impl<'t, 'o> Freeze for TokenOutputTrimmer<'t, 'o>

§

impl<'t, 'o> !RefUnwindSafe for TokenOutputTrimmer<'t, 'o>

§

impl<'t, 'o> !Send for TokenOutputTrimmer<'t, 'o>

§

impl<'t, 'o> !Sync for TokenOutputTrimmer<'t, 'o>

§

impl<'t, 'o> Unpin for TokenOutputTrimmer<'t, 'o>

§

impl<'t, 'o> !UnwindSafe for TokenOutputTrimmer<'t, 'o>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.