use std::fmt;
use std::marker::PhantomData;
use std::str::FromStr;
use serde::de;
use serde::de::Visitor;
use crate::wire::decimal::parse_canonical_decimal;
pub(in crate::wire::decimal) struct DecimalVisitor<T>(
pub(in crate::wire::decimal) PhantomData<T>,
);
impl<'de, T> Visitor<'de> for DecimalVisitor<T>
where
T: FromStr + fmt::Display,
T::Err: fmt::Display,
{
type Value = T;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a decimal string")
}
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: de::Error,
{
parse_canonical_decimal(value)
}
fn visit_string<E>(self, value: String) -> Result<Self::Value, E>
where
E: de::Error,
{
self.visit_str(&value)
}
}