pub enum Condition {
KeyValue {
key: ConditionKey,
value: 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.
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) -> bool
pub fn evaluate(&self, platform: &TargetPlatform) -> bool
Evaluate this condition against platform. The result
is fully determined by platform and the condition’s
AST — no global state, no environment lookup, no I/O.
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>
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 Eq 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
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.