use crate::en::Encoder;
pub trait Encode<M> {
const IS_BITWISE_ENCODE: bool = false;
type Encode: ?Sized + Encode<M>;
fn encode<E>(&self, encoder: E) -> Result<(), E::Error>
where
E: Encoder<Mode = M>;
#[inline]
fn size_hint(&self) -> Option<usize> {
None
}
fn as_encode(&self) -> &Self::Encode;
}
impl<T, M> Encode<M> for &T
where
T: ?Sized + Encode<M>,
{
type Encode = T;
const IS_BITWISE_ENCODE: bool = false;
#[inline]
fn encode<E>(&self, encoder: E) -> Result<(), E::Error>
where
E: Encoder<Mode = M>,
{
(**self).encode(encoder)
}
#[inline]
fn size_hint(&self) -> Option<usize> {
(**self).size_hint()
}
#[inline]
fn as_encode(&self) -> &Self::Encode {
self
}
}
impl<T, M> Encode<M> for &mut T
where
T: ?Sized + Encode<M>,
{
type Encode = T;
const IS_BITWISE_ENCODE: bool = false;
#[inline]
fn encode<E>(&self, encoder: E) -> Result<(), E::Error>
where
E: Encoder<Mode = M>,
{
(**self).encode(encoder)
}
#[inline]
fn size_hint(&self) -> Option<usize> {
(**self).size_hint()
}
#[inline]
fn as_encode(&self) -> &Self::Encode {
self
}
}