Skip to main content

Features

Struct Features 

Source
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

Source

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).

Source

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.

Source

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 Clone for Features

Source§

fn clone(&self) -> Features

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Features

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Features

Source§

fn default() -> Features

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Features

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Features

Source§

fn eq(&self, other: &Features) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Features

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Features

Source§

impl StructuralPartialEq for Features

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,