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