1 | use crate::{bindgen_prelude::*, check_status, sys, ValueType}; |
2 | |
3 | impl TypeName for bool { |
4 | fn type_name() -> &'static str { |
5 | "bool" |
6 | } |
7 | |
8 | fn value_type() -> ValueType { |
9 | ValueType::Boolean |
10 | } |
11 | } |
12 | |
13 | impl ValidateNapiValue for bool {} |
14 | |
15 | impl ToNapiValue for bool { |
16 | unsafe fn to_napi_value(env: sys::napi_env, val: bool) -> Result<sys::napi_value> { |
17 | let mut ptr: *mut napi_value__ = std::ptr::null_mut(); |
18 | |
19 | check_status!( |
20 | unsafe { sys::napi_get_boolean(env, val, &mut ptr) }, |
21 | "Failed to convert rust type `bool` into napi value" , |
22 | )?; |
23 | |
24 | Ok(ptr) |
25 | } |
26 | } |
27 | |
28 | impl FromNapiValue for bool { |
29 | unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> Result<Self> { |
30 | let mut ret: bool = false; |
31 | |
32 | check_status!( |
33 | unsafe { sys::napi_get_value_bool(env, napi_val, &mut ret) }, |
34 | "Failed to convert napi value into rust type `bool`" , |
35 | )?; |
36 | |
37 | Ok(ret) |
38 | } |
39 | } |
40 | |