pub enum Condition {
KeyValue {
key: ConditionKey,
value: String,
},
Feature(String),
CompilerFamily {
slot: CompilerSlot,
family: CompilerKind,
},
CompilerVersionReq {
slot: CompilerSlot,
req: String,
},
All(Vec<Condition>),
Any(Vec<Condition>),
Not(Box<Condition>),
}Expand description
Typed AST for a cfg(...) target condition.
The wire format matches the manifest text: a key/value
(key = "value") leaf, or one of the all / any / not
combinators. Equality and ordering are structural, so
identical expressions always compare equal regardless of
whitespace or quote style in the original source.
Variants§
KeyValue
key = "value". The key is restricted to the
ConditionKey set; the value is a free-form ASCII
string interpreted by evaluate.
Feature(String)
feature = "name". Evaluates against the enabled-feature
set of the package the condition belongs to, not the
platform. Feature conditions are only meaningful - and only
accepted - in flag tables ([target.'cfg(...)'.profile]);
the manifest layer rejects a feature-referencing cfg that
gates a dependency table, because feature resolution itself
runs over the dependency graph and a feature→dependency edge
would be circular.
CompilerFamily
cc = "<family>" / cxx = "<family>". Matches when the
detected compiler in that slot is the named family
(crate::compiler::CompilerKind ids). When detection has
not run (fail-soft commands) or the slot is unresolved, the
detected family counts as unknown, which is matchable.
Compiler conditions are accepted on profile flag tables
only; the manifest layer rejects them on dependency /
toolchain / cache tables, where detection is unavailable.
CompilerVersionReq
cc_version = "<req>" / cxx_version = "<req>". The value
is a SemVer requirement (the same grammar as dependency
versions, parsed leniently) matched against the detected
version zero-padded to major.minor.patch. No detected
version ⇒ false. The raw requirement string is preserved
verbatim so Display round-trips byte-identically.
All(Vec<Condition>)
all(<conditions>). Empty all() is rejected at parse
time.
Any(Vec<Condition>)
any(<conditions>). Empty any() is rejected at parse
time.
Not(Box<Condition>)
not(<single condition>).
Implementations§
Source§impl Condition
impl Condition
Sourcepub fn parse_cfg(input: &str) -> Result<Self, ConditionParseError>
pub fn parse_cfg(input: &str) -> Result<Self, ConditionParseError>
Parse a full cfg(...) expression. The wrapping
cfg(...) is required so the parser is symmetric with
the manifest text users write.
§Errors
Returns ConditionParseError::ExpectedCfgPrefix when the input is not
wrapped in cfg(, ConditionParseError::UnbalancedParens when the
trailing ) is missing, and propagates any ConditionParseError from
parsing the inner expression.
Sourcepub fn parse_inner(input: &str) -> Result<Self, ConditionParseError>
pub fn parse_inner(input: &str) -> Result<Self, ConditionParseError>
Parse the inner expression of a cfg(...) form (no
cfg( prefix or trailing )). Useful for the metadata
round-trip path, where we store the inner form.
§Errors
Returns a ConditionParseError when the expression is malformed -
e.g. an unsupported key, a missing = or quoted value, an empty
all()/any(), a not() of wrong arity, unbalanced parentheses, or
trailing input after the expression.
Sourcepub fn evaluate(&self, ctx: &ConditionContext<'_>) -> bool
pub fn evaluate(&self, ctx: &ConditionContext<'_>) -> bool
Evaluate this condition against the typed
ConditionContext - the host platform, the set of
features enabled on the owning package, and the detected
compiler identities. The result is fully determined by
those inputs and the condition’s AST - no global state, no
environment lookup, no I/O.
Contexts that carry no feature information (every
dependency-gating call) use
ConditionContext::platform_only; this is
correct-by-construction because a feature-referencing cfg
is rejected on dependency tables at manifest-load time, so a
Feature leaf can only be reached here through a flag table
that threaded the real enabled-feature set in.
Sourcepub fn references_feature(&self) -> bool
pub fn references_feature(&self) -> bool
Whether this condition references any feature = "..."
leaf. Used by the manifest layer to reject feature
conditions on dependency tables (where they would be
circular) while allowing them on flag tables.
Sourcepub fn references_compiler(&self) -> bool
pub fn references_compiler(&self) -> bool
Whether this condition references any compiler leaf
(cc / cxx / cc_version / cxx_version). Used by the
manifest layer to reject compiler conditions on tables
evaluated before toolchain detection runs (dependencies,
toolchain or compiler-wrapper selection).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Condition
impl<'de> Deserialize<'de> for Condition
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
impl Eq for Condition
Source§impl Ord for Condition
impl Ord for Condition
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Condition
impl PartialOrd for Condition
impl StructuralPartialEq for Condition
Auto Trait Implementations§
impl Freeze for Condition
impl RefUnwindSafe for Condition
impl Send for Condition
impl Sync for Condition
impl Unpin for Condition
impl UnsafeUnpin for Condition
impl UnwindSafe for Condition
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.