Skip to main content

image_ndarray/
error.rs

1//! Error type shared by the image-ndarray conversions.
2
3use thiserror::Error;
4
5/// Global error object for the image-ndarray crate.
6#[derive(Debug, Error, PartialEq)]
7pub enum Error {
8    /// The array shape is inconsistent with its element count (wraps `ndarray::ShapeError`).
9    #[cfg(feature = "image")]
10    #[error("NDArray had an error during initialization of shape: {0}")]
11    NDArray(#[from] ndarray::ShapeError),
12    /// The image container rejected the converted buffer, for example because its length is wrong.
13    #[error("Image could not be constructed from ndarray")]
14    ImageConstructFailed,
15    /// The array's last axis length differs from the image pixel's channel count.
16    #[error(
17        "Image could not be constructed from ndarray because output does not match input channel count"
18    )]
19    ChannelMismatch,
20    /// The array is not 2D or 3D, or its width or height does not fit in `u32`.
21    #[error("Only 2d and 3d arrays are supported")]
22    Dimensions,
23}
24
25/// Result alias for conversions that can fail with [`Error`].
26#[cfg(feature = "image")]
27pub type Result<T> = core::result::Result<T, Error>;