use alloc::string::String;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum RawError {
#[error("RAW decode error: {0}")]
Decode(String),
#[error("invalid input: {0}")]
InvalidInput(String),
#[error("unsupported: {0}")]
Unsupported(String),
#[error("limit exceeded: {0}")]
LimitExceeded(String),
#[error("stopped: {0}")]
Stopped(enough::StopReason),
#[error("buffer error: {0}")]
Buffer(zenpixels::BufferError),
}
impl From<enough::StopReason> for RawError {
fn from(reason: enough::StopReason) -> Self {
RawError::Stopped(reason)
}
}
impl From<zenpixels::BufferError> for RawError {
fn from(e: zenpixels::BufferError) -> Self {
RawError::Buffer(e)
}
}
pub(crate) trait IntoBufferError {
fn into_buffer_error(self) -> zenpixels::BufferError;
}
impl IntoBufferError for zenpixels::BufferError {
fn into_buffer_error(self) -> zenpixels::BufferError {
self
}
}
impl IntoBufferError for whereat::At<zenpixels::BufferError> {
fn into_buffer_error(self) -> zenpixels::BufferError {
self.decompose().0
}
}
#[cfg(feature = "rawloader")]
impl From<rawloader::RawLoaderError> for RawError {
fn from(e: rawloader::RawLoaderError) -> Self {
RawError::Decode(e.to_string())
}
}
pub type Result<T> = core::result::Result<T, whereat::At<RawError>>;