use std::borrow::Cow;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("unexpected end of data at offset {offset}: expected {expected} bytes, got {actual}")]
UnexpectedEof {
offset: u64,
expected: usize,
actual: usize,
},
#[error("invalid data source range: {0}")]
InvalidRange(Cow<'static, str>),
#[error("invalid format: {0}")]
InvalidFormat(Cow<'static, str>),
#[error("invalid source reference: {0}")]
InvalidSourceReference(Cow<'static, str>),
#[error("not found: {0}")]
NotFound(Cow<'static, str>),
#[error("unsupported: {0}")]
Unsupported(Cow<'static, str>),
}
impl Error {
pub fn invalid_range(message: impl Into<Cow<'static, str>>) -> Self {
Self::InvalidRange(message.into())
}
pub fn invalid_format(message: impl Into<Cow<'static, str>>) -> Self {
Self::InvalidFormat(message.into())
}
pub fn invalid_source_reference(message: impl Into<Cow<'static, str>>) -> Self {
Self::InvalidSourceReference(message.into())
}
pub fn not_found(message: impl Into<Cow<'static, str>>) -> Self {
Self::NotFound(message.into())
}
pub fn unsupported(message: impl Into<Cow<'static, str>>) -> Self {
Self::Unsupported(message.into())
}
}
pub type Result<T> = std::result::Result<T, Error>;