use thiserror::Error;
#[derive(Clone, Copy, Debug, Eq, Error, Hash, PartialEq)]
pub enum CodecEncodeError<E> {
#[error("codec encode error at input index {input_index}: {source}")]
Encode {
#[source]
source: E,
input_index: usize,
},
#[error("codec encode reset error: {source}")]
EncodeReset {
#[source]
source: E,
},
#[error("codec encode flush error: {source}")]
EncodeFlush {
#[source]
source: E,
},
#[error("unencodable value at input index {input_index}")]
UnencodableValue {
input_index: usize,
},
}
impl<E> CodecEncodeError<E> {
#[inline(always)]
#[must_use]
pub const fn encode(source: E, input_index: usize) -> Self {
Self::Encode {
source,
input_index,
}
}
#[inline(always)]
#[must_use]
pub const fn encode_reset(source: E) -> Self {
Self::EncodeReset { source }
}
#[inline(always)]
#[must_use]
pub const fn encode_flush(source: E) -> Self {
Self::EncodeFlush { source }
}
#[inline(always)]
#[must_use]
pub const fn unencodable_value(input_index: usize) -> Self {
Self::UnencodableValue { input_index }
}
#[inline(always)]
#[must_use]
pub fn into_source(self) -> Option<E> {
match self {
Self::Encode { source, .. }
| Self::EncodeReset { source }
| Self::EncodeFlush { source } => Some(source),
Self::UnencodableValue { .. } => None,
}
}
}