use core::fmt;
pub type Result<T> = core::result::Result<T, MjpegError>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MjpegError {
InvalidData(String),
Unsupported(String),
Other(String),
Eof,
NeedMore,
}
impl MjpegError {
pub fn invalid(msg: impl Into<String>) -> Self {
Self::InvalidData(msg.into())
}
pub fn unsupported(msg: impl Into<String>) -> Self {
Self::Unsupported(msg.into())
}
pub fn other(msg: impl Into<String>) -> Self {
Self::Other(msg.into())
}
}
impl fmt::Display for MjpegError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidData(s) => write!(f, "invalid data: {s}"),
Self::Unsupported(s) => write!(f, "unsupported: {s}"),
Self::Other(s) => write!(f, "other: {s}"),
Self::Eof => write!(f, "end of stream"),
Self::NeedMore => write!(f, "need more data"),
}
}
}
impl std::error::Error for MjpegError {}