use crate::{
_tags, DOC_INVALID_VALUE, DOC_NOT_IMPLEMENTED, DOC_NOT_SUPPORTED, InvalidValue, NotImplemented,
NotSupported, Sign, define_error,
};
define_error![individual: pub struct NoInverse;
#[derive(Default)], +location: "num/error", +tag: _tags!(num),
DOC_NO_INVERSE = "An inverse doesn't exist.",
self+f => f.write_str(DOC_NO_INVERSE!()),
];
define_error![individual: pub struct MismatchedSizes;
#[derive(Default)], +location: "num/error", +tag: _tags!(num),
DOC_MISMATCHED_SIZES = "The provided values are not compatible in size.",
self+f => f.write_str(DOC_MISMATCHED_SIZES!()),
];
define_error![individual: pub struct IncompatibleBounds;
#[derive(Default)], +location: "num/error", +tag: _tags!(num),
DOC_INCOMPATIBLE_BOUNDS = "The given bounds are incompatible.
E.g. lower bound exceeds upper bound.", self+f => f.write_str("The given bounds are incompatible."),
];
define_error![individual: pub struct NonNegativeRequired;
#[derive(Default)], +location: "num/error", +tag: _tags!(num),
DOC_NON_NEGATIVE_REQUIRED = "A non-negative value is required.",
self+f => f.write_str(DOC_NON_NEGATIVE_REQUIRED!()),
];
define_error![individual: pub struct PositiveRequired;
#[derive(Default)], +location: "num/error", +tag: _tags!(num),
DOC_POSITIVE_REQUIRED = "A positive value is required.",
self+f => f.write_str(DOC_POSITIVE_REQUIRED!()),
];
define_error![individual: pub struct NonZeroRequired;
#[derive(Default)], +location: "num/error", +tag: _tags!(num),
DOC_NON_ZERO_REQUIRED = "A non-zero value is required.",
self+f => f.write_str(DOC_NON_ZERO_REQUIRED!()),
];
define_error![individual: pub struct Overflow(pub Option<Sign>);
#[derive(Default)], +location: "num/error", +tag: _tags!(num),
DOC_OVERFLOW = "An arithmetic overflow error, with an optional associated sign.",
self+f => if let Some(sign) = self.0 {
match sign {
Sign::Positive => f.write_str("Positive overflow."),
Sign::Negative => f.write_str("Negative overflow."),
Sign::Zero => f.write_str("Unsigned overflow."), }
} else {
f.write_str("Overflow.")
},
];
define_error! { composite: fmt(f)
#[doc = crate::_doc_location!("num/error")]
pub enum IntError {
+tag: _tags!(no),
DOC_NOT_IMPLEMENTED: +const NotImplemented => NotImplemented,
+tag: _tags!(no),
DOC_NOT_SUPPORTED: +const NotSupported => NotSupported,
DOC_OVERFLOW: +const Overflow(s|0: Option<Sign>) => Overflow(*s),
DOC_NO_INVERSE: +const NoInverse => NoInverse,
DOC_NON_NEGATIVE_REQUIRED: +const NonNegativeRequired => NonNegativeRequired,
DOC_NON_ZERO_REQUIRED: +const NonZeroRequired => NonZeroRequired,
DOC_MISMATCHED_SIZES: +const MismatchedSizes => MismatchedSizes,
}
}
#[allow(dead_code)]
impl IntError {
#[doc(hidden)]
pub const fn ni<T>() -> IntResult<T> {
Err(IntError::NotImplemented)
}
}
#[doc = crate::_tags!(num result)]
#[doc = crate::_doc_location!("num")]
pub type IntResult<T> = crate::Result<T, IntError>;
define_error! { composite: fmt(f)
#[doc = crate::_doc_location!("num")]
pub enum NicheValueError {
+tag: _tags!(num),
DOC_OVERFLOW: +const Overflow(s|0: Option<Sign>) => Overflow(*s),
DOC_INVALID_VALUE: +const InvalidValue => InvalidValue,
}
}