cql_to_rust: Implement FromCqlVal for BTreeMap
@@ -3,7 +3,7 @@ use crate::frame::value::Counter;
use bigdecimal::BigDecimal;
use chrono::{Duration, NaiveDate};
use num_bigint::BigInt;
-use std::collections::{BTreeSet, HashMap, HashSet};
+use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::hash::Hash;
use std::net::IpAddr;
use thiserror::Error;
@@ -137,6 +137,19 @@ impl<T: FromCqlVal<CqlValue> + Ord> FromCqlVal<CqlValue> for BTreeSet<T> {
}
}
+impl<K: FromCqlVal<CqlValue> + Ord, V: FromCqlVal<CqlValue>> FromCqlVal<CqlValue>
+ for BTreeMap<K, V>
+{
+ fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
+ let vec = cql_val.into_pair_vec().ok_or(FromCqlValError::BadCqlType)?;
+ let mut res = BTreeMap::new();
+ for (key, value) in vec {
+ res.insert(K::from_cql(key)?, V::from_cql(value)?);
+ }
+ Ok(res)
+ }
+}
+
macro_rules! replace_expr {
($_t:tt $sub:expr) => {
$sub
