feat: add more function
This commit is contained in:
parent
21640d695b
commit
2cf731316b
1 changed files with 18 additions and 1 deletions
19
src/lib.rs
19
src/lib.rs
|
@ -12,7 +12,7 @@ use std::string::String as RustString;
|
||||||
mod executor;
|
mod executor;
|
||||||
pub mod sys;
|
pub mod sys;
|
||||||
|
|
||||||
pub use sys::Status;
|
pub use sys::{napi_valuetype, Status};
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
pub type Callback = extern "C" fn(sys::napi_env, sys::napi_callback_info) -> sys::napi_value;
|
pub type Callback = extern "C" fn(sys::napi_env, sys::napi_callback_info) -> sys::napi_value;
|
||||||
|
@ -834,6 +834,17 @@ impl<'env> Value<'env, Object> {
|
||||||
Ok(is_array)
|
Ok(is_array)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_buffer(&self) -> Result<bool> {
|
||||||
|
let mut is_buffer = false;
|
||||||
|
let status = unsafe { sys::napi_is_buffer(self.raw_env(), self.raw_value(), &mut is_buffer) };
|
||||||
|
check_status(status)?;
|
||||||
|
Ok(is_buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_buffer(&self) -> Value<'env, Buffer> {
|
||||||
|
Value::from_raw(self.env, self.raw_value)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_array_length(&self) -> Result<u32> {
|
pub fn get_array_length(&self) -> Result<u32> {
|
||||||
if self.is_array()? != true {
|
if self.is_array()? != true {
|
||||||
return Err(Error {
|
return Err(Error {
|
||||||
|
@ -905,6 +916,12 @@ impl<'env> Value<'env, Function> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'env> Value<'env, Any> {
|
||||||
|
pub fn get_type(&self) -> sys::napi_valuetype {
|
||||||
|
get_raw_type(self.env.0, self.raw_value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> Drop for Ref<T> {
|
impl<T> Drop for Ref<T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in a new issue