napi_h/
value_type.rs

1use std::fmt::{Display, Formatter, Result};
2
3use crate::sys;
4
5#[repr(i32)]
6#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash)]
7pub enum ValueType {
8  Undefined = 0,
9  Null = 1,
10  Boolean = 2,
11  Number = 3,
12  String = 4,
13  Symbol = 5,
14  Object = 6,
15  Function = 7,
16  External = 8,
17  #[cfg(feature = "napi6")]
18  BigInt = 9,
19  Unknown = 1024,
20}
21
22impl Display for ValueType {
23  fn fmt(&self, f: &mut Formatter<'_>) -> Result {
24    let status_string = format!("{:?}", self);
25    write!(f, "{}", status_string)
26  }
27}
28
29impl From<i32> for ValueType {
30  fn from(value: i32) -> ValueType {
31    match value {
32      #[cfg(feature = "napi6")]
33      sys::ValueType::napi_bigint => ValueType::BigInt,
34      sys::ValueType::napi_boolean => ValueType::Boolean,
35      sys::ValueType::napi_external => ValueType::External,
36      sys::ValueType::napi_function => ValueType::Function,
37      sys::ValueType::napi_null => ValueType::Null,
38      sys::ValueType::napi_number => ValueType::Number,
39      sys::ValueType::napi_object => ValueType::Object,
40      sys::ValueType::napi_string => ValueType::String,
41      sys::ValueType::napi_symbol => ValueType::Symbol,
42      sys::ValueType::napi_undefined => ValueType::Undefined,
43      _ => ValueType::Unknown,
44    }
45  }
46}