pub trait SubstParseContext: Sized {
type NotInPaste: Debug + Copy + Sized;
type NotInConcat: Debug + Copy + Sized;
type NotInBool: Debug + Copy + Sized;
type ConcatOnly: Debug + Copy + Sized;
type BoolOnly: Debug + Copy + Sized;
type DbgContent: Parse + Debug + AnalyseRepeat + FindRecogMetas;
type SpecialParseContext: SpecialParseContext + Default;
const IS_BOOL: bool = false;
// Required methods
fn not_in_paste(span: &impl Spanned) -> Result<Self::NotInPaste>;
fn not_in_concat(span: &impl Spanned) -> Result<Self::NotInConcat>;
fn not_in_bool(span: &impl Spanned) -> Result<Self::NotInBool>;
// Provided methods
fn bool_only(span: &impl Spanned) -> Result<Self::BoolOnly> { ... }
fn concat_only(span: &impl Spanned) -> Result<Self::ConcatOnly> { ... }
fn meta_recog_usage(m: &SubstMeta<Self>) -> UsageInfo<IsUsed> { ... }
fn parse_maybe_within_parens<T>(
input: ParseStream<'_>,
f: impl FnOnce(ParseStream<'_>) -> Result<T>,
) -> Result<T> { ... }
fn parse_maybe_comma(input: ParseStream<'_>) -> Result<()> { ... }
fn missing_keyword_arguments(kw_span: Span) -> Result<Void> { ... }
}Expand description
Surrounding lexical context during parsing
This is the kind of lexical context a piece of a template appears in. It is implemented for
- Types that represent an expansion output
ExpansionOutput; in this case, the lexical context is one where the expansion is accumulated in this type. - Places where template substitution syntax
${keyword }appears but where no output will be generated (eg, within the condition of${if }.
The associated types are either Void or ().
They appears within the variants of SubstDetails,
causing inapplicable variants to be eliminated.
Because a variant is only inhabited if all of its fields are,
the conditions are effectively ANDed.
So the “default” value (for context that don’t have an opnion)
is inhabitedness ().
Each type has an associated constructur, used during parsing. So this generates a parse error at parse time, if a construct appears in the wrong place.
Provided Associated Constants§
Required Associated Types§
Sourcetype NotInPaste: Debug + Copy + Sized
type NotInPaste: Debug + Copy + Sized
Uninhabited iff this lexical context is within ${paste }
Sourcetype NotInConcat: Debug + Copy + Sized
type NotInConcat: Debug + Copy + Sized
Uninhabited iff this lexical context is within ${concat }
Sourcetype NotInBool: Debug + Copy + Sized
type NotInBool: Debug + Copy + Sized
Uninhabited iff this lexical context is within a condition.
Sourcetype ConcatOnly: Debug + Copy + Sized
type ConcatOnly: Debug + Copy + Sized
Uninhabited unless this lexical context is within ${concat }
Sourcetype BoolOnly: Debug + Copy + Sized
type BoolOnly: Debug + Copy + Sized
Uninhabited unless this lexical context is within a condition.
Sourcetype DbgContent: Parse + Debug + AnalyseRepeat + FindRecogMetas
type DbgContent: Parse + Debug + AnalyseRepeat + FindRecogMetas
Content of the dbg keyword
This has to be in this trait because
${dbg } contains a Template but dbg(...) contains a Subst.
For all ExpansionContext impls, should be Template<Self>.
We make bespoke output for each context; for boolean this is sui
generis, and for expansions it’s in ExpansionOutput::dbg_expand.
Sourcetype SpecialParseContext: SpecialParseContext + Default
type SpecialParseContext: SpecialParseContext + Default
For communicating through parse_special
Used when parsing ${paste ..} to handle
the special >-based end condition.
Required Methods§
fn not_in_paste(span: &impl Spanned) -> Result<Self::NotInPaste>
fn not_in_concat(span: &impl Spanned) -> Result<Self::NotInConcat>
fn not_in_bool(span: &impl Spanned) -> Result<Self::NotInBool>
Provided Methods§
fn bool_only(span: &impl Spanned) -> Result<Self::BoolOnly>
fn concat_only(span: &impl Spanned) -> Result<Self::ConcatOnly>
Sourcefn meta_recog_usage(m: &SubstMeta<Self>) -> UsageInfo<IsUsed>
fn meta_recog_usage(m: &SubstMeta<Self>) -> UsageInfo<IsUsed>
When we find a fmeta etc. in this context, does it allow a value?
Used by the template-scanning code, to report whether an Xmeta
in the template justifies a value-bearing Xmeta attribute
on/in the driver, or just a boolean.
Sourcefn parse_maybe_within_parens<T>(
input: ParseStream<'_>,
f: impl FnOnce(ParseStream<'_>) -> Result<T>,
) -> Result<T>
fn parse_maybe_within_parens<T>( input: ParseStream<'_>, f: impl FnOnce(ParseStream<'_>) -> Result<T>, ) -> Result<T>
Parse using f, within parens in boolean context, not otherwise
Useful for parsing the arguments to an argument-taking keyword which takes an “equivalent” syntax in both contexts.
Sourcefn parse_maybe_comma(input: ParseStream<'_>) -> Result<()>
fn parse_maybe_comma(input: ParseStream<'_>) -> Result<()>
Parse maybe a comma (comma in boolean contegxt, not otherwise)
Useful for parsing the arguments to an argument-taking keyword which takes an “equivalent” syntax in both contexts.
Sourcefn missing_keyword_arguments(kw_span: Span) -> Result<Void>
fn missing_keyword_arguments(kw_span: Span) -> Result<Void>
Return an error suitable for reporting missing arguments
Helper for handling missing arguments to an argument-taking keyword which takes an “equivalent” syntax in both contexts.
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.