MCPcopy Create free account
hub / github.com/0xKarl-dev/claw-codes / optional_string_array

Function optional_string_array

rust/crates/runtime/src/config.rs:853–879  ·  view source on GitHub ↗
(
    object: &BTreeMap<String, JsonValue>,
    key: &str,
    context: &str,
)

Source from the content-addressed store, hash-verified

851}
852
853fn 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
881fn optional_string_map(
882 object: &BTreeMap<String, JsonValue>,

Calls 3

as_arrayMethod · 0.80
getMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected