feat(napi): implement value getter for JsNumber
This commit is contained in:
parent
aa3f0932c8
commit
50ce9c6569
1 changed files with 30 additions and 0 deletions
|
@ -6,6 +6,36 @@ use crate::{sys, Error, Result};
|
||||||
|
|
||||||
pub struct JsNumber(pub(crate) Value);
|
pub struct JsNumber(pub(crate) Value);
|
||||||
|
|
||||||
|
impl JsNumber {
|
||||||
|
#[inline]
|
||||||
|
pub fn get_uint32(&self) -> Result<u32> {
|
||||||
|
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<i32> {
|
||||||
|
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<i64> {
|
||||||
|
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<f64> {
|
||||||
|
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<JsNumber> for u32 {
|
impl TryFrom<JsNumber> for u32 {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue