#[non_exhaustive]pub enum OxiNumError {
Parse(Cow<'static, str>),
Precision(Cow<'static, str>),
DivByZero,
Overflow(Cow<'static, str>),
InvalidRadix(u32),
Domain(Cow<'static, str>),
}Expand description
Errors from OxiNum operations.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Parse(Cow<'static, str>)
Failed to parse a number from a string.
Precision(Cow<'static, str>)
Precision constraint violated.
DivByZero
Division by zero.
Overflow(Cow<'static, str>)
Arithmetic overflow (e.g. result exceeds a primitive range).
InvalidRadix(u32)
Invalid radix for base conversion (must be 2..=36).
Domain(Cow<'static, str>)
Input is outside the domain of the function (e.g. sqrt of a negative).
Implementations§
Source§impl OxiNumError
impl OxiNumError
Sourcepub fn context(self, ctx: impl AsRef<str>) -> Self
pub fn context(self, ctx: impl AsRef<str>) -> Self
Returns a new error of the same variant with ctx prepended to the
message, for message-bearing variants.
For variants without a free-form message (DivByZero, InvalidRadix)
the original value is returned unchanged because their Display
already conveys the kind precisely.
§Examples
use oxinum_core::OxiNumError;
let e = OxiNumError::Parse("bad digit".into()).context("while reading row 4");
assert!(e.to_string().contains("while reading row 4:"));
assert!(e.to_string().contains("bad digit"));
// Variants without a message are returned untouched.
assert_eq!(
OxiNumError::DivByZero.context("noop"),
OxiNumError::DivByZero,
);Trait Implementations§
Source§impl Clone for OxiNumError
impl Clone for OxiNumError
Source§fn clone(&self) -> OxiNumError
fn clone(&self) -> OxiNumError
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OxiNumError
impl Debug for OxiNumError
Source§impl Display for OxiNumError
impl Display for OxiNumError
Source§impl Error for OxiNumError
impl Error for OxiNumError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<OxiNumError> for Error
impl From<OxiNumError> for Error
Source§fn from(e: OxiNumError) -> Self
fn from(e: OxiNumError) -> Self
Converts to this type from the input type.
Source§impl From<ParseNumberError> for OxiNumError
impl From<ParseNumberError> for OxiNumError
Source§fn from(e: ParseNumberError) -> Self
fn from(e: ParseNumberError) -> Self
Converts to this type from the input type.
Source§impl PartialEq for OxiNumError
impl PartialEq for OxiNumError
Source§fn eq(&self, other: &OxiNumError) -> bool
fn eq(&self, other: &OxiNumError) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for OxiNumError
impl StructuralPartialEq for OxiNumError
Auto Trait Implementations§
impl Freeze for OxiNumError
impl RefUnwindSafe for OxiNumError
impl Send for OxiNumError
impl Sync for OxiNumError
impl Unpin for OxiNumError
impl UnsafeUnpin for OxiNumError
impl UnwindSafe for OxiNumError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more