cargo_feature_matrix/config.rs
1use crate::features::{FeatureMatrix, FeatureSet};
2use figment::{
3 value::{Dict, Map},
4 Error, Figment, Metadata, Profile, Provider,
5};
6use serde::{Deserialize, Serialize};
7use std::collections::HashSet;
8
9#[derive(Default, Serialize, Deserialize)]
10#[non_exhaustive]
11#[serde(bound(deserialize = "'de: 'c"))]
12pub struct Config<'c> {
13 /// If this set is not empty, only these features will be used to construct the
14 /// matrix.
15 pub seed: FeatureSet<'c>,
16
17 /// All of these features will be included in every feature set in the matrix.
18 pub include: FeatureSet<'c>,
19
20 /// Any feature set that includes any of these will be excluded from the matrix.
21 /// This includes features enabled by other features.
22 ///
23 /// This can be used for things like having an "__unstable" feature that gets
24 /// enabled by any other features that use unstable rust features and then
25 /// excluding "__unstable" if not on nightly.
26 pub deny: FeatureSet<'c>,
27
28 /// These sets will be dropped from the matrix.
29 pub skip: FeatureMatrix<'c>,
30
31 /// Some crates prepend internal features with a double underscore. If this
32 /// flag is not set, those features will not be used to build the matrix, but
33 /// will be allowed if they are enabled by other features.
34 pub include_hidden: bool,
35
36 /// List sets of features that can't be used together. Any generated feature
37 /// set that is a superset of any of these sets will be dropped from the matrix.
38 pub conflict: HashSet<FeatureSet<'c>>,
39}
40
41impl Config<'_> {
42 pub fn from<T: Provider>(provider: T) -> Result<Self, Error> {
43 Figment::from(provider).extract()
44 }
45
46 pub fn figment() -> Figment {
47 Figment::from(Config::default())
48 }
49}
50
51impl Provider for Config<'_> {
52 fn metadata(&self) -> Metadata {
53 Metadata::named("Config object")
54 }
55
56 fn data(&self) -> Result<Map<Profile, Dict>, Error> {
57 figment::providers::Serialized::defaults(self).data()
58 }
59}