use super::Encoding;
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub enum Padding {
Forbidden,
Optional,
Required,
Internal,
#[default]
Standard,
}
impl Padding {
#[inline]
pub(crate) const fn encode_padded(self) -> bool {
matches!(self, Self::Standard | Self::Required)
}
#[inline]
pub(crate) const fn decode_allows_padding(self) -> bool {
!matches!(self, Self::Forbidden)
}
#[inline]
pub(crate) const fn decode_requires_padding(self) -> bool {
matches!(self, Self::Required)
}
#[inline]
pub(crate) const fn decode_allows_internal_padding(self) -> bool {
matches!(self, Self::Internal)
}
}
#[derive(Clone, Debug)]
pub struct WithPad<'a, T> {
pub(crate) encoding: &'a T,
pub(crate) pad: Padding,
}
impl<'a, T> WithPad<'a, T> {
#[inline]
pub const fn new(encoding: &'a T, pad: Padding) -> Self {
WithPad { encoding, pad }
}
#[inline]
pub const fn pad(&self, pad: Padding) -> WithPad<'a, T> {
WithPad { encoding: self.encoding, pad }
}
}
impl<T> WithPad<'_, T> where Self: Encoding {
impl_encoding!();
}