ExpansionOutput

Trait ExpansionOutput 

Source
pub trait ExpansionOutput: SubstParseContext {
Show 14 methods // Required methods fn append_identfrag_toks<I: IdentFrag>( &mut self, ident: &I, ) -> Result<(), I::BadIdent>; fn append_idpath<A, B, I>( &mut self, template_entry_span: Span, pre: A, ident: &I, post: B, grouping: Grouping, ) -> Result<(), I::BadIdent> where A: FnOnce(&mut TokenAccumulator), B: FnOnce(&mut TokenAccumulator), I: IdentFrag; fn append_syn_litstr(&mut self, v: &LitStr); fn append_syn_type_inner( &mut self, te_span: Span, v: Type, grouping: Grouping, ); fn append_tokens_with( &mut self, allow_tokens: &(<Self as SubstParseContext>::NotInPaste, <Self as SubstParseContext>::NotInConcat), f: impl FnOnce(&mut TokenAccumulator) -> Result<()>, ) -> Result<()>; fn append_bool_only(&mut self, bool_only: &Self::BoolOnly) -> !; fn record_error(&mut self, err: Error); fn new_with_span(kw_span: Span) -> Self; fn ignore_impl(self) -> Result<()>; fn dbg_expand<'c>( &mut self, kw_span: Span, ctx: GeneralContext<'c>, msg: &mut String, content: &Self::DbgContent, ) -> Result; // Provided methods fn append_syn_type(&mut self, te_span: Span, v: Type, grouping: Grouping) { ... } fn write_error<S: Spanned, M: Display>(&mut self, span: &S, message: M) { ... } fn append_tokens( &mut self, allow_tokens: &(<Self as SubstParseContext>::NotInPaste, <Self as SubstParseContext>::NotInConcat), tokens: impl ToTokens, ) -> Result<()> { ... } fn default_subst_meta_as(kw: Span) -> Result<SubstAs<Self>> { ... }
}
Expand description

Expansion output accumulator, for a template lexical context

Each template lexical context has a distinct type which

  • Represents the lexical context
  • If that lexical context generates expansions, accumulates the expansion. That’s what this trait is.

The methods are for accumulating various kinds of things that can be found in templates, or result from template expansion.

The accumulating type (Self might be accumulating tokens (TokenStream) or strings (paste::Items).

Required Methods§

Source

fn append_identfrag_toks<I: IdentFrag>( &mut self, ident: &I, ) -> Result<(), I::BadIdent>

An identifier (or fragment of one)

Uses the IdentFragment for identifier pasting, and the ToTokens for general expansion.

Source

fn append_idpath<A, B, I>( &mut self, template_entry_span: Span, pre: A, ident: &I, post: B, grouping: Grouping, ) -> Result<(), I::BadIdent>

Append a Rust path (scoped identifier, perhaps with generics)

To facilitate ${pawte }, the path is provided as:

  • some prefix tokens (e.g., a scoping path),
  • the actual identifer,
  • some suffix tokens (e.g. generics).

tspan is the span of the part of the template which expanded into this path.

This is a “more complex” expansion, in the terminology of the template reference: If a paste contains more than one, it is an error.

Source

fn append_syn_litstr(&mut self, v: &LitStr)

Append a syn::LitStr

This is its own method because syn::LitStr is not Display, and we don’t want to unconditionally turn it into a string before retokenising it.

Source

fn append_syn_type_inner(&mut self, te_span: Span, v: Type, grouping: Grouping)

Append a syn::Type, which has been grouping-normalised

Source

fn append_tokens_with( &mut self, allow_tokens: &(<Self as SubstParseContext>::NotInPaste, <Self as SubstParseContext>::NotInConcat), f: impl FnOnce(&mut TokenAccumulator) -> Result<()>, ) -> Result<()>

Append using a function which generates tokens

If you have an impl ToTokens, use append_tokens instead.

Not supported within ${paste }. The NotInPaste parameter makes this method unreachable when expanding within ${paste }; or to put it another way, it ensures that such an attempt would have been rejected during template parsing.

Source

fn append_bool_only(&mut self, bool_only: &Self::BoolOnly) -> !

“Append” a substitution which can only be used within a boolean

Such a thing cannot be expanded, so it cannot be appended, so this function must be unreachable. expand_bool_only is called (in expansion contexts) to handle uninhabited SubstDetails variants etc.

Implementing it involves demonstrating that either self, or Self::BoolOnly, is uninhabited, with a call to [void::unreachable].

Source

fn record_error(&mut self, err: Error)

Note that an error occurred

This must arrange to (eventually) convert it using into_compile_error and emit it somewhere appropriate.

Source

fn new_with_span(kw_span: Span) -> Self

Make a new empty expansion output, introduced at kw_span

Normally, call sites use an inherent constructor method. This one is used for special cases, eg ${ignore ...}

Source

fn ignore_impl(self) -> Result<()>

Implement the core of the ignore keyword

If there was an error, returns it. Otherwise, discards everything.

Source

fn dbg_expand<'c>( &mut self, kw_span: Span, ctx: GeneralContext<'c>, msg: &mut String, content: &Self::DbgContent, ) -> Result

Implement the dbg keyword

Specifically:

  • Write the expansion of child to msg in human-readable form
  • Without a trailing newline
  • Subsume it into self

Expansion errors are to be reported, and subsumed into self. Failures to write may be thrown.

Provided Methods§

Source

fn append_syn_type(&mut self, te_span: Span, v: Type, grouping: Grouping)

Append a syn::Type

This is a “more complex” expansion, in the terminology of the template reference: If a paste contains more than one, it is an error.

Source

fn write_error<S: Spanned, M: Display>(&mut self, span: &S, message: M)

Convenience method for noting an error with span and message

Source

fn append_tokens( &mut self, allow_tokens: &(<Self as SubstParseContext>::NotInPaste, <Self as SubstParseContext>::NotInConcat), tokens: impl ToTokens, ) -> Result<()>

Convenience method for writing a ToTokens

Dispatches to append_tokens_with Not supported within ${paste }.

Source

fn default_subst_meta_as(kw: Span) -> Result<SubstAs<Self>>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§