feat(napi): impl from/to NapiValue for JsUnkown

This commit is contained in:
LongYinan 2021-10-29 18:50:29 +08:00
parent 698bc701e8
commit e709f25635

View file

@ -1,4 +1,4 @@
use crate::{check_status, sys, Error, Result, Status, ValueType};
use crate::{check_status, sys, Error, JsUnknown, Result, Status, ValueType};
use std::ptr;
mod array;
@ -32,6 +32,12 @@ pub trait ToNapiValue {
unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> Result<sys::napi_value>;
}
impl ToNapiValue for JsUnknown {
unsafe fn to_napi_value(_env: sys::napi_env, val: Self) -> Result<sys::napi_value> {
Ok(val.0.value)
}
}
pub trait FromNapiValue: Sized {
/// # Safety
///
@ -39,6 +45,16 @@ pub trait FromNapiValue: Sized {
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> Result<Self>;
}
impl FromNapiValue for JsUnknown {
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> Result<Self> {
Ok(JsUnknown(crate::Value {
env,
value: napi_val,
value_type: crate::ValueType::Unknown,
}))
}
}
pub trait FromNapiRef {
/// # Safety
///