pub enum Condition {
KeyValue {
key: ConditionKey,
value: String,
},
Feature(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.
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,
platform: &TargetPlatform,
features: &BTreeSet<String>,
) -> bool
pub fn evaluate( &self, platform: &TargetPlatform, features: &BTreeSet<String>, ) -> bool
Evaluate this condition against platform and the set of
features enabled on the owning package. The result is
fully determined by those inputs and the condition’s AST —
no global state, no environment lookup, no I/O.
Platform contexts that carry no feature information (every
dependency-gating call) pass an empty set; 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.
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.