2020-11-11 13:15:13 +09:00
|
|
|
use std::fmt::{Display, Formatter, Result};
|
2018-04-28 17:26:38 +09:00
|
|
|
|
2020-11-11 13:15:13 +09:00
|
|
|
use crate::sys;
|
|
|
|
|
|
|
|
#[repr(i32)]
|
2020-05-06 00:13:23 +09:00
|
|
|
#[derive(Eq, PartialEq, Debug, Clone, Copy)]
|
2018-04-28 17:26:38 +09:00
|
|
|
pub enum Status {
|
2020-11-11 13:15:13 +09:00
|
|
|
Ok = 0,
|
2018-04-28 17:26:38 +09:00
|
|
|
InvalidArg,
|
|
|
|
ObjectExpected,
|
|
|
|
StringExpected,
|
|
|
|
NameExpected,
|
|
|
|
FunctionExpected,
|
|
|
|
NumberExpected,
|
|
|
|
BooleanExpected,
|
|
|
|
ArrayExpected,
|
|
|
|
GenericFailure,
|
|
|
|
PendingException,
|
|
|
|
Cancelled,
|
|
|
|
EscapeCalledTwice,
|
|
|
|
HandleScopeMismatch,
|
|
|
|
CallbackScopeMismatch,
|
2020-11-11 13:15:13 +09:00
|
|
|
/// ThreadSafeFunction queue is full
|
2019-02-22 12:04:13 +09:00
|
|
|
QueueFull,
|
2020-11-11 13:15:13 +09:00
|
|
|
/// ThreadSafeFunction closed
|
2019-02-22 12:04:13 +09:00
|
|
|
Closing,
|
|
|
|
BigintExpected,
|
2020-11-11 13:15:13 +09:00
|
|
|
DateExpected,
|
|
|
|
ArrayBufferExpected,
|
|
|
|
DetachableArraybufferExpected,
|
|
|
|
WouldDeadlock,
|
|
|
|
Unknown = 1024, // unknown status. for example, using napi3 module in napi7 NodeJS, and generate an invalid napi3 status
|
2018-04-28 17:26:38 +09:00
|
|
|
}
|
|
|
|
|
2020-11-11 13:15:13 +09:00
|
|
|
impl Display for Status {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
|
|
|
let status_string = format!("{:?}", self);
|
|
|
|
write!(f, "{}", status_string)
|
2018-04-28 17:26:38 +09:00
|
|
|
}
|
|
|
|
}
|
2020-05-01 02:26:56 +09:00
|
|
|
|
2020-11-11 13:15:13 +09:00
|
|
|
impl From<i32> for Status {
|
|
|
|
fn from(code: i32) -> Self {
|
|
|
|
match code {
|
|
|
|
sys::Status::napi_ok => Status::Ok,
|
|
|
|
sys::Status::napi_invalid_arg => Status::InvalidArg,
|
|
|
|
sys::Status::napi_object_expected => Status::ObjectExpected,
|
|
|
|
sys::Status::napi_string_expected => Status::StringExpected,
|
|
|
|
sys::Status::napi_name_expected => Status::NameExpected,
|
|
|
|
sys::Status::napi_function_expected => Status::FunctionExpected,
|
|
|
|
sys::Status::napi_number_expected => Status::NumberExpected,
|
|
|
|
sys::Status::napi_boolean_expected => Status::BooleanExpected,
|
|
|
|
sys::Status::napi_array_expected => Status::ArrayExpected,
|
|
|
|
sys::Status::napi_generic_failure => Status::GenericFailure,
|
|
|
|
sys::Status::napi_pending_exception => Status::PendingException,
|
|
|
|
sys::Status::napi_cancelled => Status::Cancelled,
|
|
|
|
sys::Status::napi_escape_called_twice => Status::EscapeCalledTwice,
|
|
|
|
sys::Status::napi_handle_scope_mismatch => Status::HandleScopeMismatch,
|
|
|
|
sys::Status::napi_callback_scope_mismatch => Status::CallbackScopeMismatch,
|
|
|
|
sys::Status::napi_queue_full => Status::QueueFull,
|
|
|
|
sys::Status::napi_closing => Status::Closing,
|
|
|
|
sys::Status::napi_bigint_expected => Status::BigintExpected,
|
|
|
|
sys::Status::napi_date_expected => Status::DateExpected,
|
|
|
|
sys::Status::napi_arraybuffer_expected => Status::ArrayBufferExpected,
|
|
|
|
sys::Status::napi_detachable_arraybuffer_expected => Status::DetachableArraybufferExpected,
|
|
|
|
sys::Status::napi_would_deadlock => Status::WouldDeadlock,
|
|
|
|
_ => Status::Unknown,
|
2020-05-01 02:26:56 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|