MCPcopy Create free account
hub / github.com/PowerShell/DSC / extract_bool

Method extract_bool

resources/sshdconfig/src/canonical_properties.rs:95–111  ·  view source on GitHub ↗

Extract and validate a boolean canonical property from a map. # Arguments `map` - The map to extract the value from `prop` - The canonical property to extract `default` - The default value to return if the property is not found # Errors Returns an error if the value exists but is not a boolean.

(
        map: &mut Map<String, Value>,
        prop: CanonicalProperty,
        default: bool,
    )

Source from the content-addressed store, hash-verified

93 ///
94 /// Returns an error if the value exists but is not a boolean.
95 pub fn extract_bool(
96 map: &mut Map<String, Value>,
97 prop: CanonicalProperty,
98 default: bool,
99 ) -> Result<bool, SshdConfigError> {
100 if let Some(value) = map.remove(prop.as_str()) {
101 if let Value::Bool(b) = value {
102 Ok(b)
103 } else {
104 Err(SshdConfigError::InvalidInput(
105 t!("canonical_properties.inputMustBeBoolean", input = prop.as_str()).to_string()
106 ))
107 }
108 } else {
109 Ok(default)
110 }
111 }
112}

Callers

nothing calls this directly

Calls 2

removeMethod · 0.80
as_strMethod · 0.80

Tested by

no test coverage detected