diff --git a/src/key.rs b/src/key.rs index eb13ed3..ca4ea53 100644 --- a/src/key.rs +++ b/src/key.rs @@ -228,7 +228,7 @@ impl ::serde::Serialize for SecretKey { impl<'de> ::serde::Deserialize<'de> for SecretKey { fn deserialize>(d: D) -> Result { if d.is_human_readable() { - d.deserialize_str(super::serde_util::HexVisitor::new( + d.deserialize_str(super::serde_util::FromStrVisitor::new( "a hex string representing 32 byte SecretKey" )) } else { @@ -442,7 +442,7 @@ impl ::serde::Serialize for PublicKey { impl<'de> ::serde::Deserialize<'de> for PublicKey { fn deserialize>(d: D) -> Result { if d.is_human_readable() { - d.deserialize_str(super::serde_util::HexVisitor::new( + d.deserialize_str(super::serde_util::FromStrVisitor::new( "an ASCII hex string representing a public key" )) } else { diff --git a/src/lib.rs b/src/lib.rs index 73a9734..8b6d374 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -444,7 +444,7 @@ impl ::serde::Serialize for Signature { impl<'de> ::serde::Deserialize<'de> for Signature { fn deserialize>(d: D) -> Result { if d.is_human_readable() { - d.deserialize_str(serde_util::HexVisitor::new( + d.deserialize_str(serde_util::FromStrVisitor::new( "a hex string representing a DER encoded Signature" )) } else { diff --git a/src/schnorrsig.rs b/src/schnorrsig.rs index cd695a3..ed09fe4 100644 --- a/src/schnorrsig.rs +++ b/src/schnorrsig.rs @@ -34,7 +34,7 @@ impl ::serde::Serialize for Signature { impl<'de> ::serde::Deserialize<'de> for Signature { fn deserialize>(d: D) -> Result { if d.is_human_readable() { - d.deserialize_str(super::serde_util::HexVisitor::new( + d.deserialize_str(super::serde_util::FromStrVisitor::new( "a hex string representing 64 byte schnorr signature" )) } else { @@ -417,7 +417,7 @@ impl ::serde::Serialize for PublicKey { impl<'de> ::serde::Deserialize<'de> for PublicKey { fn deserialize>(d: D) -> Result { if d.is_human_readable() { - d.deserialize_str(super::serde_util::HexVisitor::new( + d.deserialize_str(super::serde_util::FromStrVisitor::new( "a hex string representing 32 byte schnorr public key" )) } else { diff --git a/src/serde_util.rs b/src/serde_util.rs index 5034416..313821a 100644 --- a/src/serde_util.rs +++ b/src/serde_util.rs @@ -3,21 +3,22 @@ use core::marker::PhantomData; use core::str::{self, FromStr}; use serde::de; -pub struct HexVisitor { +/// A serde visitor that works for `T`s implementing `FromStr`. +pub struct FromStrVisitor { expectation: &'static str, _pd: PhantomData, } -impl HexVisitor { +impl FromStrVisitor { pub fn new(expectation: &'static str) -> Self { - HexVisitor { + FromStrVisitor { expectation, _pd: PhantomData, } } } -impl<'de, T> de::Visitor<'de> for HexVisitor +impl<'de, T> de::Visitor<'de> for FromStrVisitor where T: FromStr, ::Err: fmt::Display,