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