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,
)
| 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 | } |