Skip to content

Commit e6e23e9

Browse files
Rename HexVisitor to FromStrVisitor
The visitor works with all types that implement `FromStr`. Whether or not that ends up being hex encoding depends on the implementation of `FromStr`.
1 parent 18890d3 commit e6e23e9

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/key.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl ::serde::Serialize for SecretKey {
228228
impl<'de> ::serde::Deserialize<'de> for SecretKey {
229229
fn deserialize<D: ::serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
230230
if d.is_human_readable() {
231-
d.deserialize_str(super::serde_util::HexVisitor::new(
231+
d.deserialize_str(super::serde_util::FromStrVisitor::new(
232232
"a hex string representing 32 byte SecretKey"
233233
))
234234
} else {
@@ -442,7 +442,7 @@ impl ::serde::Serialize for PublicKey {
442442
impl<'de> ::serde::Deserialize<'de> for PublicKey {
443443
fn deserialize<D: ::serde::Deserializer<'de>>(d: D) -> Result<PublicKey, D::Error> {
444444
if d.is_human_readable() {
445-
d.deserialize_str(super::serde_util::HexVisitor::new(
445+
d.deserialize_str(super::serde_util::FromStrVisitor::new(
446446
"an ASCII hex string representing a public key"
447447
))
448448
} else {

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl ::serde::Serialize for Signature {
444444
impl<'de> ::serde::Deserialize<'de> for Signature {
445445
fn deserialize<D: ::serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
446446
if d.is_human_readable() {
447-
d.deserialize_str(serde_util::HexVisitor::new(
447+
d.deserialize_str(serde_util::FromStrVisitor::new(
448448
"a hex string representing a DER encoded Signature"
449449
))
450450
} else {

src/schnorrsig.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl ::serde::Serialize for Signature {
3434
impl<'de> ::serde::Deserialize<'de> for Signature {
3535
fn deserialize<D: ::serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
3636
if d.is_human_readable() {
37-
d.deserialize_str(super::serde_util::HexVisitor::new(
37+
d.deserialize_str(super::serde_util::FromStrVisitor::new(
3838
"a hex string representing 64 byte schnorr signature"
3939
))
4040
} else {
@@ -417,7 +417,7 @@ impl ::serde::Serialize for PublicKey {
417417
impl<'de> ::serde::Deserialize<'de> for PublicKey {
418418
fn deserialize<D: ::serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
419419
if d.is_human_readable() {
420-
d.deserialize_str(super::serde_util::HexVisitor::new(
420+
d.deserialize_str(super::serde_util::FromStrVisitor::new(
421421
"a hex string representing 32 byte schnorr public key"
422422
))
423423
} else {

src/serde_util.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@ use core::marker::PhantomData;
33
use core::str::{self, FromStr};
44
use serde::de;
55

6-
pub struct HexVisitor<T> {
6+
/// A serde visitor that works for `T`s implementing `FromStr`.
7+
pub struct FromStrVisitor<T> {
78
expectation: &'static str,
89
_pd: PhantomData<T>,
910
}
1011

11-
impl<T> HexVisitor<T> {
12+
impl<T> FromStrVisitor<T> {
1213
pub fn new(expectation: &'static str) -> Self {
13-
HexVisitor {
14+
FromStrVisitor {
1415
expectation,
1516
_pd: PhantomData,
1617
}
1718
}
1819
}
1920

20-
impl<'de, T> de::Visitor<'de> for HexVisitor<T>
21+
impl<'de, T> de::Visitor<'de> for FromStrVisitor<T>
2122
where
2223
T: FromStr,
2324
<T as FromStr>::Err: fmt::Display,

0 commit comments

Comments
 (0)