use core::marker::PhantomData;
use serde::de::DeserializeOwned;
use serde_json::Error as JsonError;
use serde_json::from_str;
use super::ValueDecoder;
#[must_use]
#[derive(Debug)]
pub struct JsonStringValueDecoder<T> {
_marker: PhantomData<T>,
}
impl<T> Copy for JsonStringValueDecoder<T> {}
impl<T> Clone for JsonStringValueDecoder<T> {
#[inline]
fn clone(&self) -> Self {
*self
}
}
impl<T> Default for JsonStringValueDecoder<T> {
#[inline]
fn default() -> Self {
Self::new()
}
}
impl<T> JsonStringValueDecoder<T> {
#[inline]
pub const fn new() -> Self {
Self { _marker: PhantomData }
}
}
impl<T> ValueDecoder<str> for JsonStringValueDecoder<T>
where
T: DeserializeOwned,
{
type Error = JsonError;
type Output = T;
#[inline]
fn decode(&mut self, input: &str) -> Result<Self::Output, Self::Error> {
from_str(input)
}
}