1use std::convert::TryFrom;
2
3use super::Value;
4use crate::bindgen_runtime::{TypeName, ValidateNapiValue};
5use crate::{check_status, ValueType};
6use crate::{sys, Error, Result};
7
8#[derive(Clone, Copy)]
9pub struct JsBoolean(pub(crate) Value);
10
11impl TypeName for JsBoolean {
12 fn type_name() -> &'static str {
13 "bool"
14 }
15
16 fn value_type() -> crate::ValueType {
17 ValueType::Boolean
18 }
19}
20
21impl ValidateNapiValue for JsBoolean {}
22
23impl JsBoolean {
24 pub fn get_value(&self) -> Result<bool> {
25 let mut result: bool = false;
26 check_status!(unsafe { sys::napi_get_value_bool(self.0.env, self.0.value, &mut result) })?;
27 Ok(result)
28 }
29}
30
31impl TryFrom<JsBoolean> for bool {
32 type Error = Error;
33
34 fn try_from(value: JsBoolean) -> Result<bool> {
35 value.get_value()
36 }
37}
38