#[repr(i32)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub enum ErrorCode {
Success = 0,
Overflow = -1,
InvalidDigit = -2,
Empty = -3,
#[doc(hidden)]
__Nonexhaustive = -4,
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct Error {
pub code: ErrorCode,
pub index: usize,
}
#[no_mangle]
pub extern fn is_success(error: Error) -> bool {
error.code == ErrorCode::Success
}
#[no_mangle]
pub extern fn is_overflow(error: Error) -> bool {
error.code == ErrorCode::Overflow
}
#[no_mangle]
pub extern fn is_invalid_digit(error: Error) -> bool {
error.code == ErrorCode::InvalidDigit
}
#[no_mangle]
pub extern fn is_empty(error: Error) -> bool {
error.code == ErrorCode::Empty
}
#[inline]
pub(crate) fn success() -> Error {
Error { code: ErrorCode::Success, index: 0 }
}
#[inline]
pub(crate) fn overflow_error() -> Error {
Error { code: ErrorCode::Overflow, index: 0 }
}
#[inline]
pub(crate) fn invalid_digit_error(index: usize) -> Error {
Error { code: ErrorCode::InvalidDigit, index: index }
}
#[inline]
pub(crate) fn empty_error() -> Error {
Error { code: ErrorCode::Empty, index: 0 }
}