ndhistogram/
error.rs

1use thiserror::Error;
2
3/// All errors that can occur in this crate can be converted into this type to
4/// make handling errors from this crate easier if the user does not care about
5/// the specific details of the cause of the error.
6#[derive(Error, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub enum Error {
9    /// Returned if a Histogram binary operation fails (such as h1 + h2).
10    #[error(transparent)]
11    BinaryOperationError(#[from] BinaryOperationError),
12    /// Returned if an Axis cannot be created due to invalid input parameters.
13    #[error(transparent)]
14    AxisError(#[from] AxisError),
15}
16
17#[derive(Error, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19/// Returned if a Histogram binary operation fails (such as h1 + h2).
20/// for example because the two histograms have incompatible binning.
21#[error("histogram binary operation failed (check binning?)")]
22pub struct BinaryOperationError;
23
24/// Errors that can occur when creating an Axis, usually due to invalid input parameters.
25#[derive(Error, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
26#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
27pub enum AxisError {
28    /// Failed to create an axis as the number of bins is invalid for this axis type.
29    #[error("number of bins should be positive and non-zero and must be convertible to the coordinate type")]
30    InvalidNumberOfBins,
31    /// Failed to create an axis due to an invalid range for this axis type (for example the low edge equaling the high edge).
32    #[error("Invalid axis range. Low edge should not equal high edge.")]
33    InvalidAxisRange,
34    /// Failed to create an axis due to an invalid step size for this axis type (for example a negative step size).
35    #[error("axis step size should be non-zero and positive")]
36    InvalidStepSize,
37    /// Failed to create an axis due to an invalid number of bin edges for this axis type.
38    #[error("the number of bin edges must be at >= 2.")]
39    InvalidNumberOfBinEdges,
40    /// Failed to create an axis as the input bin edges are not sortable. This can happen if one of the bin edges is NaN.
41    #[error("failed to sort bin_edges. The list of axis bin edges must be sortable.")]
42    FailedToSortBinEdges,
43}