diff --git a/napi/src/js_values/number.rs b/napi/src/js_values/number.rs index a81f45d5..b0cd3624 100644 --- a/napi/src/js_values/number.rs +++ b/napi/src/js_values/number.rs @@ -6,6 +6,36 @@ use crate::{sys, Error, Result}; pub struct JsNumber(pub(crate) Value); +impl JsNumber { + #[inline] + pub fn get_uint32(&self) -> Result { + let mut result = 0; + check_status!(unsafe { sys::napi_get_value_uint32(self.0.env, self.0.value, &mut result) })?; + Ok(result) + } + + #[inline] + pub fn get_int32(&self) -> Result { + let mut result = 0; + check_status!(unsafe { sys::napi_get_value_int32(self.0.env, self.0.value, &mut result) })?; + Ok(result) + } + + #[inline] + pub fn get_int64(&self) -> Result { + let mut result = 0; + check_status!(unsafe { sys::napi_get_value_int64(self.0.env, self.0.value, &mut result) })?; + Ok(result) + } + + #[inline] + pub fn get_double(&self) -> Result { + let mut result = 0_f64; + check_status!(unsafe { sys::napi_get_value_double(self.0.env, self.0.value, &mut result) })?; + Ok(result) + } +} + impl TryFrom for u32 { type Error = Error;