Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schema): for hashes #294

Merged
merged 5 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading