diff options
Diffstat (limited to 'src/object')
-rw-r--r-- | src/object/parser.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/object/parser.rs b/src/object/parser.rs index 5879e9a..d80e38c 100644 --- a/src/object/parser.rs +++ b/src/object/parser.rs @@ -90,3 +90,19 @@ impl Value { self.as_class("vector").ok()?.remove("Array")?.as_array() } } + +impl<K: FromValue + Ord, V: FromValue> FromValue for BTreeMap<K, V> { + fn from_value(v: Value) -> Result<Self> { + v.as_class("map")? + .remove("Array") + .ok_or(anyhow!("map is missing Array field"))? + .as_array() + .ok_or(anyhow!("map Array field is not an array"))? + .into_iter() + .map(|e| { + let mut fields = e.as_class("pair")?; + Ok((fields.field("first")?, fields.field("second")?)) + }) + .collect::<Result<BTreeMap<_, _>>>() + } +} |