napi-rs/napi/src/status.rs

88 lines
3.1 KiB
Rust
Raw Normal View History

use crate::sys::napi_status;
2018-04-28 17:26:38 +09:00
#[derive(Eq, PartialEq, Debug, Clone, Copy)]
2018-04-28 17:26:38 +09:00
pub enum Status {
Ok,
InvalidArg,
ObjectExpected,
StringExpected,
NameExpected,
FunctionExpected,
NumberExpected,
BooleanExpected,
ArrayExpected,
GenericFailure,
PendingException,
Cancelled,
EscapeCalledTwice,
HandleScopeMismatch,
CallbackScopeMismatch,
2020-11-10 12:09:25 +09:00
#[cfg(feature = "napi4")]
2019-02-22 12:04:13 +09:00
QueueFull,
2020-11-10 12:09:25 +09:00
#[cfg(feature = "napi4")]
2019-02-22 12:04:13 +09:00
Closing,
2020-11-10 12:09:25 +09:00
#[cfg(feature = "napi6")]
2019-02-22 12:04:13 +09:00
BigintExpected,
Unknown,
2018-04-28 17:26:38 +09:00
}
impl From<napi_status> for Status {
fn from(code: napi_status) -> Self {
use Status::*;
match code {
napi_status::napi_ok => Ok,
napi_status::napi_invalid_arg => InvalidArg,
napi_status::napi_object_expected => ObjectExpected,
napi_status::napi_string_expected => StringExpected,
napi_status::napi_name_expected => NameExpected,
napi_status::napi_function_expected => FunctionExpected,
napi_status::napi_number_expected => NumberExpected,
napi_status::napi_boolean_expected => BooleanExpected,
napi_status::napi_array_expected => ArrayExpected,
napi_status::napi_generic_failure => GenericFailure,
napi_status::napi_pending_exception => PendingException,
napi_status::napi_cancelled => Cancelled,
napi_status::napi_escape_called_twice => EscapeCalledTwice,
napi_status::napi_handle_scope_mismatch => HandleScopeMismatch,
napi_status::napi_callback_scope_mismatch => CallbackScopeMismatch,
2020-11-10 12:09:25 +09:00
#[cfg(feature = "napi4")]
napi_status::napi_queue_full => QueueFull,
2020-11-10 12:09:25 +09:00
#[cfg(feature = "napi4")]
napi_status::napi_closing => Closing,
2020-11-10 12:09:25 +09:00
#[cfg(feature = "napi6")]
napi_status::napi_bigint_expected => BigintExpected,
2019-02-22 12:04:13 +09:00
_ => Unknown,
2018-04-28 17:26:38 +09:00
}
}
}
impl Into<self::napi_status> for Status {
fn into(self) -> napi_status {
match self {
Self::Ok => napi_status::napi_ok,
Self::InvalidArg => napi_status::napi_invalid_arg,
Self::ObjectExpected => napi_status::napi_object_expected,
Self::StringExpected => napi_status::napi_string_expected,
Self::NameExpected => napi_status::napi_name_expected,
Self::FunctionExpected => napi_status::napi_function_expected,
Self::NumberExpected => napi_status::napi_number_expected,
Self::BooleanExpected => napi_status::napi_boolean_expected,
Self::ArrayExpected => napi_status::napi_array_expected,
Self::GenericFailure => napi_status::napi_generic_failure,
Self::PendingException => napi_status::napi_pending_exception,
Self::Cancelled => napi_status::napi_cancelled,
Self::EscapeCalledTwice => napi_status::napi_escape_called_twice,
Self::HandleScopeMismatch => napi_status::napi_handle_scope_mismatch,
Self::CallbackScopeMismatch => napi_status::napi_callback_scope_mismatch,
2020-11-10 12:09:25 +09:00
#[cfg(feature = "napi4")]
Self::QueueFull => napi_status::napi_queue_full,
2020-11-10 12:09:25 +09:00
#[cfg(feature = "napi4")]
Self::Closing => napi_status::napi_closing,
2020-11-10 12:09:25 +09:00
#[cfg(feature = "napi6")]
Self::BigintExpected => napi_status::napi_bigint_expected,
Self::Unknown => napi_status::napi_generic_failure,
}
}
}