diff --git a/src/shape.rs b/src/shape.rs index e3595b6..6ca3dbd 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -3,7 +3,7 @@ // TODO: handle recursive types! use crate::traits::ShapeContext; use crate::BinProtShape; -use std::collections::BTreeMap; +use std::collections::{BTreeMap, HashMap}; // In the OCaml version, uuids are used as strings. #[derive(Debug, Clone, PartialEq, Eq)] @@ -235,6 +235,32 @@ impl BinProtShape for Vec { } } +fn iterable_binable1_shape(caller_identity: Uuid, bin_shape_el: Shape) -> Shape { + Shape::Base( + caller_identity, + vec![Shape::Base(Uuid::from("ac8a9ff4-4994-11e6-9a1b-9fb4e933bd9d"), vec![bin_shape_el])], + ) +} + +impl BinProtShape for HashMap +where + S: 'static, +{ + fn binprot_shape_impl(c: &mut ShapeContext) -> Shape { + let caller_identity = Uuid::from("8fabab0a-4992-11e6-8cca-9ba2c4686d9e"); + let bin_shape_el = Shape::Tuple(vec![K::binprot_shape_loop(c), V::binprot_shape_loop(c)]); + iterable_binable1_shape(caller_identity, bin_shape_el) + } +} + +impl BinProtShape for BTreeMap { + fn binprot_shape_impl(c: &mut ShapeContext) -> Shape { + let caller_identity = Uuid::from("dfb300f8-4992-11e6-9c15-73a2ac6b815c"); + let bin_shape_el = Shape::Tuple(vec![K::binprot_shape_loop(c), V::binprot_shape_loop(c)]); + iterable_binable1_shape(caller_identity, bin_shape_el) + } +} + impl BinProtShape for Option { fn binprot_shape_impl(c: &mut ShapeContext) -> Shape { Shape::Base(Uuid::from("option"), vec![T::binprot_shape_loop(c)]) @@ -297,5 +323,13 @@ mod tests { Shape::Application(Box::new(inner), vec![]) }; assert_eq!(digest_str(&shape_rec), "2e92d51efb901fcf492f243fc1c3601d"); + let shape_i64_i64_hashtbl = { + std::collections::HashMap::::binprot_shape_impl(&mut ShapeContext::default()) + }; + assert_eq!(digest_str(&shape_i64_i64_hashtbl), "1fd943a5d8026fbd3e6746c972ab2127"); + let shape_i64_i64_btreemap = { + std::collections::BTreeMap::::binprot_shape_impl(&mut ShapeContext::default()) + }; + assert_eq!(digest_str(&shape_i64_i64_btreemap), "ed73a010af8ffc32cab7411d6be2d676"); } }