Skip to content

Commit

Permalink
feat(schema): for HashMap<K, V> -> HashMap<K, V, S>, for `HashSet…
Browse files Browse the repository at this point in the history
…<T>` -> `HashSet<T, S>` (#294)

* assert variant too suprising

* may be this right?

* and set

* clean

* why
  • Loading branch information
dzmitry-lahoda authored May 30, 2024
1 parent fa6225c commit cdb8fa9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 7 additions & 2 deletions borsh/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,11 @@ pub mod hashes {
#[cfg(not(feature = "std"))]
use alloc::format;

impl<K, V> BorshSchema for HashMap<K, V>
// 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<K, V, S> BorshSchema for HashMap<K, V, S>
where
K: BorshSchema,
V: BorshSchema,
Expand All @@ -715,7 +719,8 @@ pub mod hashes {
format!(r#"HashMap<{}, {}>"#, K::declaration(), V::declaration())
}
}
impl<T> BorshSchema for HashSet<T>

impl<T, S> BorshSchema for HashSet<T, S>
where
T: BorshSchema,
{
Expand Down
5 changes: 2 additions & 3 deletions borsh/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down

0 comments on commit cdb8fa9

Please sign in to comment.