#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub enum ErrorCode {
Overflow = -1,
Underflow = -2,
InvalidDigit = -3,
Empty = -4,
EmptyFraction = -5,
EmptyExponent = -6,
#[doc(hidden)]
__Nonexhaustive = -7,
}
#[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 }
}
}
pub(crate) mod error_ffi {
pub use super::{Error, ErrorCode};
#[no_mangle]
pub extern fn error_is_overflow(error: Error) -> bool {
error.code == ErrorCode::Overflow
}
#[no_mangle]
pub extern fn error_is_underflow(error: Error) -> bool {
error.code == ErrorCode::Underflow
}
#[no_mangle]
pub extern fn error_is_invalid_digit(error: Error) -> bool {
error.code == ErrorCode::InvalidDigit
}
#[no_mangle]
pub extern fn error_is_empty(error: Error) -> bool {
error.code == ErrorCode::Empty
}
#[no_mangle]
pub extern fn error_is_empty_fraction(error: Error) -> bool {
error.code == ErrorCode::EmptyFraction
}
#[no_mangle]
pub extern fn error_is_empty_exponent(error: Error) -> bool {
error.code == ErrorCode::EmptyExponent
}
}