From cdb8fa9bf7652df1b5e85b985045ee30e62ba5ae Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Thu, 30 May 2024 19:13:44 +0100 Subject: [PATCH] feat(schema): for `HashMap` -> `HashMap`, for `HashSet` -> `HashSet` (#294) * assert variant too suprising * may be this right? * and set * clean * why --- borsh/src/schema.rs | 9 +++++++-- borsh/src/ser/mod.rs | 5 ++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/borsh/src/schema.rs b/borsh/src/schema.rs index 936050267..1fd0059e0 100644 --- a/borsh/src/schema.rs +++ b/borsh/src/schema.rs @@ -696,7 +696,11 @@ pub mod hashes { #[cfg(not(feature = "std"))] use alloc::format; - impl BorshSchema for HashMap + // S is not serialized, so we ignore it in schema too + // forcing S to be BorshSchema forces to define Definition + // which must be empty, but if not - it will fail + // so better to ignore it + impl BorshSchema for HashMap where K: BorshSchema, V: BorshSchema, @@ -715,7 +719,8 @@ pub mod hashes { format!(r#"HashMap<{}, {}>"#, K::declaration(), V::declaration()) } } - impl BorshSchema for HashSet + + impl BorshSchema for HashSet where T: BorshSchema, { diff --git a/borsh/src/ser/mod.rs b/borsh/src/ser/mod.rs index c7a2c96eb..bb1980806 100644 --- a/borsh/src/ser/mod.rs +++ b/borsh/src/ser/mod.rs @@ -384,9 +384,8 @@ pub mod hashes { u32::try_from(vec.len()) .map_err(|_| ErrorKind::InvalidData)? .serialize(writer)?; - for (key, value) in vec { - key.serialize(writer)?; - value.serialize(writer)?; + for kv in vec { + kv.serialize(writer)?; } Ok(()) }