(
object: &BTreeMap<String, JsonValue>,
key: &str,
context: &str,
)
| 851 | } |
| 852 | |
| 853 | fn optional_string_array( |
| 854 | object: &BTreeMap<String, JsonValue>, |
| 855 | key: &str, |
| 856 | context: &str, |
| 857 | ) -> Result<Option<Vec<String>>, ConfigError> { |
| 858 | match object.get(key) { |
| 859 | Some(value) => { |
| 860 | let Some(array) = value.as_array() else { |
| 861 | return Err(ConfigError::Parse(format!( |
| 862 | "{context}: field {key} must be an array" |
| 863 | ))); |
| 864 | }; |
| 865 | array |
| 866 | .iter() |
| 867 | .map(|item| { |
| 868 | item.as_str().map(ToOwned::to_owned).ok_or_else(|| { |
| 869 | ConfigError::Parse(format!( |
| 870 | "{context}: field {key} must contain only strings" |
| 871 | )) |
| 872 | }) |
| 873 | }) |
| 874 | .collect::<Result<Vec<_>, _>>() |
| 875 | .map(Some) |
| 876 | } |
| 877 | None => Ok(None), |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | fn optional_string_map( |
| 882 | object: &BTreeMap<String, JsonValue>, |
no test coverage detected