(
object: &BTreeMap<String, JsonValue>,
key: &str,
context: &str,
)
| 717 | } |
| 718 | |
| 719 | fn optional_string_array( |
| 720 | object: &BTreeMap<String, JsonValue>, |
| 721 | key: &str, |
| 722 | context: &str, |
| 723 | ) -> Result<Option<Vec<String>>, ConfigError> { |
| 724 | match object.get(key) { |
| 725 | Some(value) => { |
| 726 | let Some(array) = value.as_array() else { |
| 727 | return Err(ConfigError::Parse(format!( |
| 728 | "{context}: field {key} must be an array" |
| 729 | ))); |
| 730 | }; |
| 731 | array |
| 732 | .iter() |
| 733 | .map(|item| { |
| 734 | item.as_str().map(ToOwned::to_owned).ok_or_else(|| { |
| 735 | ConfigError::Parse(format!( |
| 736 | "{context}: field {key} must contain only strings" |
| 737 | )) |
| 738 | }) |
| 739 | }) |
| 740 | .collect::<Result<Vec<_>, _>>() |
| 741 | .map(Some) |
| 742 | } |
| 743 | None => Ok(None), |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | fn optional_string_map( |
| 748 | object: &BTreeMap<String, JsonValue>, |
no test coverage detected