Skip to main content

napi/js_values/
undefined.rs

1use crate::{
2  bindgen_runtime::{FromNapiValue, TypeName, ValidateNapiValue},
3  sys, JsValue, Result, ValueType,
4};
5
6use super::Value;
7
8#[deprecated(since = "3.0.0", note = "use `()` instead")]
9#[derive(Clone, Copy)]
10pub struct JsUndefined(pub(crate) Value);
11
12impl TypeName for JsUndefined {
13  fn type_name() -> &'static str {
14    "undefined"
15  }
16
17  fn value_type() -> crate::ValueType {
18    ValueType::Undefined
19  }
20}
21
22impl ValidateNapiValue for JsUndefined {}
23
24impl JsValue<'_> for JsUndefined {
25  fn value(&self) -> Value {
26    self.0
27  }
28}
29
30impl FromNapiValue for JsUndefined {
31  unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> Result<Self> {
32    Ok(Self(Value {
33      env,
34      value: napi_val,
35      value_type: ValueType::Undefined,
36    }))
37  }
38}