pub struct Features {
pub default: Vec<String>,
pub features: BTreeMap<String, Vec<String>>,
}Expand description
[features] declarations for a package.
Feature names are stable identifiers. The default group lists
which features are enabled by default; other entries declare
individual features and what enabling them implies.
Each entry on the right-hand side of a feature is a string in
one of three documented forms (parsed lazily into
FeatureEntry by the feature resolver):
"feature_name"— enables another local feature on the same package (transitive feature implication)."dep:dependency_name"— enables an optional Cabin package dependency declared by this package’s[dependencies]table."dependency_name/feature_name"— requests a specific feature on a Cabin package dependency. If the dependency is optional, this form also enables it.
The on-disk shape stays a flat list of strings so older readers and the canonical metadata format remain byte-identical for packages that only use the local-feature form.
Fields§
§default: Vec<String>Default features. Empty when there is no default entry in
[features].
features: BTreeMap<String, Vec<String>>Declared features and their implication lists. Stored as a
BTreeMap so iteration is deterministic and output is stable.
Implementations§
Source§impl Features
impl Features
Sourcepub fn new(
default: Vec<String>,
features: BTreeMap<String, Vec<String>>,
) -> Result<Self, ValidationError>
pub fn new( default: Vec<String>, features: BTreeMap<String, Vec<String>>, ) -> Result<Self, ValidationError>
Convenience constructor for Package::new-style call sites.
§Errors
Returns a ValidationError when the resulting feature set fails
Features::validate (see that method for the specific conditions).
Sourcepub fn validate(&self) -> Result<(), ValidationError>
pub fn validate(&self) -> Result<(), ValidationError>
Validate identifier grammar, the reserved default key,
internal references between local features, and local
cycles. dep: / dep/feature entries are validated for
grammar only; the feature resolver checks that the
referenced dependency exists, that it is optional when
dep: is used, and that the requested feature exists on
the dependency package — those checks need the package
graph and therefore happen one layer up.
§Errors
Returns ValidationError::ReservedFeatureName when default is used
as a declared feature, ValidationError::UnknownFeatureReference for a
default or implication pointing at an undeclared local feature,
ValidationError::InvalidFeatureEntry for a malformed implication
entry, a cycle error from Self::detect_cycles, and any identifier
grammar error from validating a feature name.
Sourcepub fn expand(&self, roots: &BTreeSet<String>) -> BTreeSet<String>
pub fn expand(&self, roots: &BTreeSet<String>) -> BTreeSet<String>
Expand a set of root feature names by transitive closure
over the local features map. Caller is responsible for
ensuring every root is a declared feature.
Entries that take the form dep:<name> or <dep>/<feature>
are skipped: they are package-level effects, not local
features, and are owned by the cross-package feature
resolver.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Features
impl<'de> Deserialize<'de> for Features
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Features
impl StructuralPartialEq for Features
Auto Trait Implementations§
impl Freeze for Features
impl RefUnwindSafe for Features
impl Send for Features
impl Sync for Features
impl Unpin for Features
impl UnsafeUnpin for Features
impl UnwindSafe for Features
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> 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.