Add bls serde_vistors file

This commit is contained in:
Paul Hauner 2019-03-08 13:19:37 +11:00
parent ec9e0bbddf
commit 5c1458ba46
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6

View File

@ -0,0 +1,20 @@
use hex;
use serde::de::{self, Visitor};
use std::fmt;
pub struct HexVisitor;
impl<'de> Visitor<'de> for HexVisitor {
type Value = Vec<u8>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a hex string (without 0x prefix)")
}
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(hex::decode(value).map_err(|e| de::Error::custom(format!("invalid hex ({:?})", e)))?)
}
}