aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs8
-rw-r--r--src/test.rs14
2 files changed, 19 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ebfde7a..1fe47bf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -56,6 +56,11 @@
//! [`Zeroize`](https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html) for
//! this crate's types.
//!
+//! The `serde` feature (disabled by default, but enabled for [docs.rs]) implements
+//! [`serde::Serialize`](https://docs.rs/serde/latest/serde/trait.Serialize.html) and
+//! [`serde::Deserialize`](https://docs.rs/serde/latest/serde/trait.Deserialize.html)
+//! for [`Hash`](struct@Hash).
+//!
//! The NEON implementation is enabled by default for AArch64 but requires the
//! `neon` feature for other ARM targets. Not all ARMv7 CPUs support NEON, and
//! enabling this feature will produce a binary that's not portable to CPUs
@@ -69,9 +74,6 @@
//! expect breaking changes between patch versions. (The "-preview" feature name
//! follows the conventions of the RustCrypto [`signature`] crate.)
//!
-//! The `serde` feature (disabled by default) enables serde compatibility for
-//! the `Hash` struct.
-//!
//! [`Hasher::update_rayon`]: struct.Hasher.html#method.update_rayon
//! [BLAKE3]: https://blake3.io
//! [Rayon]: https://github.com/rayon-rs/rayon
diff --git a/src/test.rs b/src/test.rs
index c98192f..fb1e849 100644
--- a/src/test.rs
+++ b/src/test.rs
@@ -806,3 +806,17 @@ fn test_mmap_rayon() -> Result<(), std::io::Error> {
);
Ok(())
}
+
+#[test]
+#[cfg(feature = "std")]
+#[cfg(feature = "serde")]
+fn test_serde() {
+ let hash: crate::Hash = [7; 32].into();
+ let json = serde_json::to_string(&hash).unwrap();
+ assert_eq!(
+ json,
+ "[7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]",
+ );
+ let hash2: crate::Hash = serde_json::from_str(&json).unwrap();
+ assert_eq!(hash, hash2);
+}