use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ParseError {
Invalid,
TooPrecise,
OutOfRange,
}
impl ParseError {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
ParseError::Invalid => "invalid decimal number",
ParseError::TooPrecise => "more than 19 decimal places",
ParseError::OutOfRange => "decimal number out of range",
}
}
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl core::error::Error for ParseError {
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct OutOfRange;
impl fmt::Display for OutOfRange {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("value out of range")
}
}
impl core::error::Error for OutOfRange {
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BufferTooSmall;
impl fmt::Display for BufferTooSmall {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("output buffer too small")
}
}
impl core::error::Error for BufferTooSmall {
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FromF64Error {
NotFinite,
OutOfRange,
}
impl fmt::Display for FromF64Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
FromF64Error::NotFinite => "f64 is NaN or infinite",
FromF64Error::OutOfRange => "f64 out of range",
})
}
}
impl core::error::Error for FromF64Error {
}
#[cfg(feature = "bigdecimal")]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TryFromBigError {
Inexact,
OutOfRange,
}
#[cfg(feature = "bigdecimal")]
impl fmt::Display for TryFromBigError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
TryFromBigError::Inexact => "more than 19 decimal places",
TryFromBigError::OutOfRange => "value out of range",
})
}
}
#[cfg(feature = "bigdecimal")]
impl core::error::Error for TryFromBigError {
}