use core::fmt;
use core::marker;
use core::ptr;
use crate::no_std::ToOwned;
use crate::context::Buffer;
use crate::de::{
AsDecoder, Decoder, NumberVisitor, PackDecoder, PairDecoder, PairsDecoder, SequenceDecoder,
SizeHint, ValueVisitor, VariantDecoder,
};
use crate::en::{Encoder, PairEncoder, PairsEncoder, SequenceEncoder, VariantEncoder};
use crate::error::Error;
use crate::Context;
pub enum NeverBuffer {}
impl Buffer for NeverBuffer {
#[inline(always)]
fn write(&mut self, _: &[u8]) -> bool {
false
}
#[inline(always)]
fn write_at(&mut self, _: usize, _: &[u8]) -> bool {
false
}
#[inline(always)]
fn copy_back<B>(&mut self, _: B) -> bool
where
B: Buffer,
{
false
}
#[inline(always)]
fn len(&self) -> usize {
0
}
fn raw_parts(&self) -> (*const u8, usize, usize) {
(ptr::null(), 0, 0)
}
#[inline(always)]
unsafe fn as_slice(&self) -> &[u8] {
&[]
}
}
#[doc(hidden)]
pub enum NeverMarker {}
pub struct Never<A, B: ?Sized = NeverMarker, C = NeverMarker> {
_never: NeverMarker,
_marker: marker::PhantomData<(A, C, B)>,
}
impl<'de, E> Decoder<'de> for Never<E>
where
E: Error,
{
type Error = E;
type Buffer = Self;
type Pack = Self;
type Sequence = Self;
type Tuple = Self;
type Map = Self;
type Some = Self;
type Struct = Self;
type Variant = Self;
type __UseMusliDecoderAttributeMacro = ();
#[inline]
fn expecting(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
match self._never {}
}
}
impl<E> AsDecoder for Never<E>
where
E: Error,
{
type Error = E;
type Decoder<'this> = Never<E>
where
Self: 'this;
#[inline]
fn as_decoder<C>(&self, _: &mut C) -> Result<Self::Decoder<'_>, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
}
impl<'de, E> PairDecoder<'de> for Never<E>
where
E: Error,
{
type Error = E;
type First<'this> = Self
where
Self: 'this;
type Second = Self;
#[inline]
fn first<C>(&mut self, _: &mut C) -> Result<Self::First<'_>, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
#[inline]
fn second<C>(self, _: &mut C) -> Result<Self::Second, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
#[inline]
fn skip_second<C>(self, _: &mut C) -> Result<bool, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
}
impl<'de, E> VariantDecoder<'de> for Never<E>
where
E: Error,
{
type Error = E;
type Tag<'this> = Self
where
Self: 'this;
type Variant<'this> = Self where Self: 'this;
#[inline]
fn tag<C>(&mut self, _: &mut C) -> Result<Self::Tag<'_>, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
#[inline]
fn variant<C>(&mut self, _: &mut C) -> Result<Self::Variant<'_>, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
#[inline]
fn skip_variant<C>(&mut self, _: &mut C) -> Result<bool, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
#[inline]
fn end<C>(self, _: &mut C) -> Result<(), C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
}
impl<'de, E> PairsDecoder<'de> for Never<E>
where
E: Error,
{
type Error = E;
type Decoder<'this> = Self
where
Self: 'this;
#[inline]
fn size_hint(&self) -> SizeHint {
match self._never {}
}
#[inline]
fn next<C>(&mut self, _: &mut C) -> Result<Option<Self::Decoder<'_>>, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
#[inline]
fn end<C>(self, _: &mut C) -> Result<(), C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
}
impl<'de, E> SequenceDecoder<'de> for Never<E>
where
E: Error,
{
type Error = E;
type Decoder<'this> = Self
where
Self: 'this;
#[inline]
fn size_hint(&self) -> SizeHint {
match self._never {}
}
#[inline]
fn next<C>(&mut self, _: &mut C) -> Result<Option<Self::Decoder<'_>>, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
#[inline]
fn end<C>(self, _: &mut C) -> Result<(), C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
}
impl<'de, E> PackDecoder<'de> for Never<E>
where
E: Error,
{
type Error = E;
type Decoder<'this> = Self
where
Self: 'this;
#[inline]
fn next<C>(&mut self, _: &mut C) -> Result<Self::Decoder<'_>, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
#[inline]
fn end<C>(self, _: &mut C) -> Result<(), C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
}
impl<O, E> Encoder for Never<O, E>
where
E: Error,
{
type Ok = O;
type Error = E;
type Pack<B> = Self where B: Buffer;
type Some = Self;
type Sequence = Self;
type Tuple = Self;
type Map = Self;
type Struct = Self;
type Variant = Self;
type __UseMusliEncoderAttributeMacro = ();
#[inline]
fn expecting(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
match self._never {}
}
}
impl<'de, O, C> NumberVisitor<'de, C> for Never<O, C>
where
C: Context,
{
type Ok = O;
fn expecting(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
match self._never {}
}
}
impl<'de, O, T, C> ValueVisitor<'de, C, T> for Never<O, T, C>
where
T: ?Sized + ToOwned,
C: Context,
{
type Ok = O;
fn expecting(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
match self._never {}
}
}
impl<O, E> SequenceEncoder for Never<O, E>
where
E: Error,
{
type Ok = O;
type Error = E;
type Encoder<'this> = Self
where
Self: 'this;
#[inline]
fn next<C>(&mut self, _: &mut C) -> Result<Self::Encoder<'_>, C::Error>
where
C: Context<Input = E>,
{
match self._never {}
}
#[inline]
fn end<C>(self, _: &mut C) -> Result<Self::Ok, C::Error>
where
C: Context<Input = E>,
{
match self._never {}
}
}
impl<O, E> PairsEncoder for Never<O, E>
where
E: Error,
{
type Ok = O;
type Error = E;
type Encoder<'this> = Self where Self: 'this;
#[inline]
fn next<C>(&mut self, _: &mut C) -> Result<Self::Encoder<'_>, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
fn end<C>(self, _: &mut C) -> Result<Self::Ok, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
}
impl<O, E> PairEncoder for Never<O, E>
where
E: Error,
{
type Ok = O;
type Error = E;
type First<'this> = Self
where
Self: 'this;
type Second<'this> = Self where Self: 'this;
#[inline]
fn first<C>(&mut self, _: &mut C) -> Result<Self::First<'_>, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
#[inline]
fn second<C>(&mut self, _: &mut C) -> Result<Self::Second<'_>, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
#[inline]
fn end<C>(self, _: &mut C) -> Result<Self::Ok, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
}
impl<O, E> VariantEncoder for Never<O, E>
where
E: Error,
{
type Ok = O;
type Error = E;
type Tag<'this> = Self
where
Self: 'this;
type Variant<'this> = Self where Self: 'this;
#[inline]
fn tag<C>(&mut self, _: &mut C) -> Result<Self::Tag<'_>, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
#[inline]
fn variant<C>(&mut self, _: &mut C) -> Result<Self::Variant<'_>, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
#[inline]
fn end<C>(self, _: &mut C) -> Result<Self::Ok, C::Error>
where
C: Context<Input = Self::Error>,
{
match self._never {}
}
}