use crate::lib::fmt::{self, Display, Formatter};
#[cfg(feature = "std")]
use std::error::Error as StdError;
#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub enum ErrorCode {
Overflow = -1,
Underflow = -2,
InvalidDigit = -3,
Empty = -4,
EmptyMantissa = -5,
EmptyExponent = -6,
EmptyInteger = -7,
EmptyFraction = -8,
InvalidPositiveMantissaSign = -9,
MissingMantissaSign = -10,
InvalidExponent = -11,
InvalidPositiveExponentSign = -12,
MissingExponentSign = -13,
ExponentWithoutFraction = -14,
InvalidLeadingZeros = -15,
#[doc(hidden)]
__Nonexhaustive = -200,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct Error {
pub code: ErrorCode,
pub index: usize,
}
impl From<ErrorCode> for Error {
#[inline]
fn from(code: ErrorCode) -> Self {
Error { code: code, index: 0 }
}
}
impl From<(ErrorCode, usize)> for Error {
#[inline]
fn from(error: (ErrorCode, usize)) -> Self {
Error { code: error.0, index: error.1 }
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "lexical error: {:?} at index {}.", self.code, self.index)
}
}
#[cfg(feature = "std")]
impl StdError for Error {}