optify/provider/
get_options_preferences.rs

1use crate::provider::{constraints::Constraints, SourceValue};
2
3#[derive(Clone, Hash, PartialEq, Eq)]
4pub struct GetOptionsPreferences {
5    /// Allows resolving configurable strings.
6    /// Defaults to false: no configurable strings will be resolved.
7    /// Configurable strings must have been enabled when the options were built to have them resolved at runtime.
8    pub are_configurable_strings_enabled: bool,
9    pub constraints: Option<Constraints>,
10    /// Overrides to apply after the built configuration.
11    pub overrides: Option<SourceValue>,
12    /// Determines if the feature names should be converted to canonical feature names.
13    /// Defaults to false: given features names will be converted to canonical feature names before looking for features or options.
14    pub skip_feature_name_conversion: bool,
15}
16
17impl Default for GetOptionsPreferences {
18    fn default() -> Self {
19        Self::new()
20    }
21}
22
23impl GetOptionsPreferences {
24    pub fn new() -> Self {
25        Self {
26            are_configurable_strings_enabled: false,
27            constraints: None,
28            overrides: None,
29            skip_feature_name_conversion: false,
30        }
31    }
32
33    pub fn set_constraints(&mut self, constraints: Option<serde_json::Value>) {
34        self.constraints = constraints.map(|c| Constraints { constraints: c });
35    }
36
37    pub fn set_constraints_json(&mut self, constraints: Option<&str>) {
38        self.constraints = constraints.map(|c| Constraints {
39            constraints: serde_json::from_str(c).expect("constraints should be valid JSON"),
40        });
41    }
42}