devela/media/image/
error.rs#[cfg(any(feature = "std", all(not(feature = "std"), feature = "io")))]
use crate::IoErrorKind;
#[doc = crate::TAG_RESULT!()]
pub type ImageResult<T> = crate::Result<T, ImageError>;
#[doc = crate::TAG_ERROR_COMPOSITE!()]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ImageError {
InvalidImageSize(Option<(usize, usize)>), InvalidPixel, InvalidMagicNumber,
InvalidParsedInteger,
FmtError,
#[cfg(any(feature = "std", all(not(feature = "std"), feature = "io")))]
#[cfg_attr(
feature = "nightly_doc",
doc(cfg(any(feature = "std", all(not(feature = "std"), feature = "io"))))
)]
IoError(IoErrorKind),
}
mod core_impls {
#[cfg(any(feature = "std", all(not(feature = "std"), feature = "io")))]
use crate::IoError;
use crate::{Display, FmtResult, Formatter, ImageError};
use core::fmt;
impl crate::Error for ImageError {}
impl crate::ExtError for ImageError {
type Kind = ();
fn error_eq(&self, other: &Self) -> bool {
self == other
}
fn error_kind(&self) -> Self::Kind {}
}
impl Display for ImageError {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult<()> {
use ImageError as E;
match self {
E::InvalidImageSize(o) => write!(f, "InvalidImageSize: {o:?}"),
E::InvalidMagicNumber => write!(f, "Invalid magic number."),
E::InvalidPixel => write!(f, "Invalid pixel."),
E::InvalidParsedInteger => write!(f, "Invalid parsed integer."),
E::FmtError => write!(f, "A core::fmt::Error."),
#[cfg(any(feature = "std", all(not(feature = "std"), feature = "io")))]
E::IoError(e) => write!(f, "An I/O Error: {e:?}"),
}
}
}
impl From<crate::ParseIntError> for ImageError {
fn from(_: crate::ParseIntError) -> Self {
Self::InvalidParsedInteger
}
}
impl From<fmt::Error> for ImageError {
fn from(_: fmt::Error) -> Self {
Self::FmtError
}
}
#[cfg(any(feature = "std", all(not(feature = "std"), feature = "io")))]
impl From<IoError> for ImageError {
fn from(e: IoError) -> Self {
Self::IoError(e.kind())
}
}
}