Merge pull request #565 from napi-rs/napi-raw
refactor: change more generic constraint from NapiValue => NapiRaw
This commit is contained in:
commit
be27e3e097
5 changed files with 19 additions and 19 deletions
|
@ -520,7 +520,7 @@ impl Env {
|
||||||
pub fn create_function_from_closure<R, F>(&self, name: &str, callback: F) -> Result<JsFunction>
|
pub fn create_function_from_closure<R, F>(&self, name: &str, callback: F) -> Result<JsFunction>
|
||||||
where
|
where
|
||||||
F: 'static + Send + Sync + Fn(crate::CallContext<'_>) -> Result<R>,
|
F: 'static + Send + Sync + Fn(crate::CallContext<'_>) -> Result<R>,
|
||||||
R: NapiValue,
|
R: NapiRaw,
|
||||||
{
|
{
|
||||||
use crate::CallContext;
|
use crate::CallContext;
|
||||||
let boxed_callback = Box::new(callback);
|
let boxed_callback = Box::new(callback);
|
||||||
|
@ -535,7 +535,7 @@ impl Env {
|
||||||
name.as_ptr(),
|
name.as_ptr(),
|
||||||
len,
|
len,
|
||||||
Some({
|
Some({
|
||||||
unsafe extern "C" fn trampoline<R: NapiValue, F: Fn(CallContext<'_>) -> Result<R>>(
|
unsafe extern "C" fn trampoline<R: NapiRaw, F: Fn(CallContext<'_>) -> Result<R>>(
|
||||||
raw_env: sys::napi_env,
|
raw_env: sys::napi_env,
|
||||||
cb_info: sys::napi_callback_info,
|
cb_info: sys::napi_callback_info,
|
||||||
) -> sys::napi_value {
|
) -> sys::napi_value {
|
||||||
|
@ -862,7 +862,7 @@ impl Env {
|
||||||
/// This API create a new reference with the specified reference count to the Object passed in.
|
/// This API create a new reference with the specified reference count to the Object passed in.
|
||||||
pub fn create_reference<T>(&self, value: T) -> Result<Ref<()>>
|
pub fn create_reference<T>(&self, value: T) -> Result<Ref<()>>
|
||||||
where
|
where
|
||||||
T: NapiValue,
|
T: NapiRaw,
|
||||||
{
|
{
|
||||||
let mut raw_ref = ptr::null_mut();
|
let mut raw_ref = ptr::null_mut();
|
||||||
let initial_ref_count = 1;
|
let initial_ref_count = 1;
|
||||||
|
@ -1066,7 +1066,7 @@ impl Env {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn create_threadsafe_function<
|
pub fn create_threadsafe_function<
|
||||||
T: Send,
|
T: Send,
|
||||||
V: NapiValue,
|
V: NapiRaw,
|
||||||
R: 'static + Send + FnMut(ThreadSafeCallContext<T>) -> Result<Vec<V>>,
|
R: 'static + Send + FnMut(ThreadSafeCallContext<T>) -> Result<Vec<V>>,
|
||||||
>(
|
>(
|
||||||
&self,
|
&self,
|
||||||
|
@ -1305,7 +1305,7 @@ impl Env {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
/// This API represents the invocation of the Strict Equality algorithm as defined in [Section 7.2.14](https://tc39.es/ecma262/#sec-strict-equality-comparison) of the ECMAScript Language Specification.
|
/// This API represents the invocation of the Strict Equality algorithm as defined in [Section 7.2.14](https://tc39.es/ecma262/#sec-strict-equality-comparison) of the ECMAScript Language Specification.
|
||||||
pub fn strict_equals<A: NapiValue, B: NapiValue>(&self, a: A, b: B) -> Result<bool> {
|
pub fn strict_equals<A: NapiRaw, B: NapiRaw>(&self, a: A, b: B) -> Result<bool> {
|
||||||
let mut result = false;
|
let mut result = false;
|
||||||
check_status!(unsafe { sys::napi_strict_equals(self.0, a.raw(), b.raw(), &mut result) })?;
|
check_status!(unsafe { sys::napi_strict_equals(self.0, a.raw(), b.raw(), &mut result) })?;
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
|
|
@ -114,7 +114,7 @@ impl JsBigint {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn instanceof<Constructor: NapiValue>(&self, constructor: Constructor) -> Result<bool> {
|
pub fn instanceof<Constructor: NapiRaw>(&self, constructor: Constructor) -> Result<bool> {
|
||||||
let mut result = false;
|
let mut result = false;
|
||||||
check_status!(unsafe {
|
check_status!(unsafe {
|
||||||
sys::napi_instanceof(self.raw.env, self.raw.value, constructor.raw(), &mut result)
|
sys::napi_instanceof(self.raw.env, self.raw.value, constructor.raw(), &mut result)
|
||||||
|
|
|
@ -2,14 +2,14 @@ use std::ops::Deref;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
use crate::check_status;
|
use crate::check_status;
|
||||||
use crate::{sys, Env, NapiRaw, NapiValue, Result};
|
use crate::{sys, Env, NapiRaw, Result};
|
||||||
|
|
||||||
pub struct EscapableHandleScope<T: NapiValue> {
|
pub struct EscapableHandleScope<T: NapiRaw> {
|
||||||
handle_scope: sys::napi_escapable_handle_scope,
|
handle_scope: sys::napi_escapable_handle_scope,
|
||||||
value: T,
|
value: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: NapiValue> EscapableHandleScope<T> {
|
impl<T: NapiRaw> EscapableHandleScope<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn open(env: sys::napi_env, value: T) -> Result<Self> {
|
pub fn open(env: sys::napi_env, value: T) -> Result<Self> {
|
||||||
let mut handle_scope = ptr::null_mut();
|
let mut handle_scope = ptr::null_mut();
|
||||||
|
@ -29,7 +29,7 @@ impl<T: NapiValue> EscapableHandleScope<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: NapiValue> Deref for EscapableHandleScope<T> {
|
impl<T: NapiRaw> Deref for EscapableHandleScope<T> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
|
||||||
fn deref(&self) -> &T {
|
fn deref(&self) -> &T {
|
||||||
|
|
|
@ -3,9 +3,9 @@ use std::ptr;
|
||||||
|
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
|
|
||||||
use crate::{check_status, sys, Env, JsError, NapiValue, Result};
|
use crate::{check_status, sys, Env, JsError, NapiRaw, Result};
|
||||||
|
|
||||||
pub struct FuturePromise<T, V: NapiValue> {
|
pub struct FuturePromise<T, V: NapiRaw> {
|
||||||
deferred: sys::napi_deferred,
|
deferred: sys::napi_deferred,
|
||||||
env: sys::napi_env,
|
env: sys::napi_env,
|
||||||
tsfn: sys::napi_threadsafe_function,
|
tsfn: sys::napi_threadsafe_function,
|
||||||
|
@ -13,9 +13,9 @@ pub struct FuturePromise<T, V: NapiValue> {
|
||||||
resolver: Box<dyn FnOnce(&mut Env, T) -> Result<V>>,
|
resolver: Box<dyn FnOnce(&mut Env, T) -> Result<V>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<T, V: NapiValue> Send for FuturePromise<T, V> {}
|
unsafe impl<T, V: NapiRaw> Send for FuturePromise<T, V> {}
|
||||||
|
|
||||||
impl<T, V: NapiValue> FuturePromise<T, V> {
|
impl<T, V: NapiRaw> FuturePromise<T, V> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn create(
|
pub fn create(
|
||||||
env: sys::napi_env,
|
env: sys::napi_env,
|
||||||
|
@ -95,7 +95,7 @@ pub(crate) async fn resolve_from_future<T: Send, F: Future<Output = Result<T>>>(
|
||||||
.expect("Failed to release thread safe function");
|
.expect("Failed to release thread safe function");
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn call_js_cb<T, V: NapiValue>(
|
unsafe extern "C" fn call_js_cb<T, V: NapiRaw>(
|
||||||
raw_env: sys::napi_env,
|
raw_env: sys::napi_env,
|
||||||
_js_callback: sys::napi_value,
|
_js_callback: sys::napi_value,
|
||||||
context: *mut c_void,
|
context: *mut c_void,
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::ptr;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{check_status, sys, Env, Error, JsError, JsFunction, NapiValue, Result, Status};
|
use crate::{check_status, sys, Env, Error, JsError, JsFunction, NapiRaw, Result, Status};
|
||||||
|
|
||||||
use sys::napi_threadsafe_function_call_mode;
|
use sys::napi_threadsafe_function_call_mode;
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ impl<T: 'static, ES: ErrorStrategy::T> ThreadsafeFunction<T, ES> {
|
||||||
/// for more information.
|
/// for more information.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn create<
|
pub fn create<
|
||||||
V: NapiValue,
|
V: NapiRaw,
|
||||||
R: 'static + Send + FnMut(ThreadSafeCallContext<T>) -> Result<Vec<V>>,
|
R: 'static + Send + FnMut(ThreadSafeCallContext<T>) -> Result<Vec<V>>,
|
||||||
>(
|
>(
|
||||||
env: sys::napi_env,
|
env: sys::napi_env,
|
||||||
|
@ -326,7 +326,7 @@ impl<T: 'static, ES: ErrorStrategy::T> Drop for ThreadsafeFunction<T, ES> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn thread_finalize_cb<T: 'static, V: NapiValue, R>(
|
unsafe extern "C" fn thread_finalize_cb<T: 'static, V: NapiRaw, R>(
|
||||||
_raw_env: sys::napi_env,
|
_raw_env: sys::napi_env,
|
||||||
finalize_data: *mut c_void,
|
finalize_data: *mut c_void,
|
||||||
_finalize_hint: *mut c_void,
|
_finalize_hint: *mut c_void,
|
||||||
|
@ -337,7 +337,7 @@ unsafe extern "C" fn thread_finalize_cb<T: 'static, V: NapiValue, R>(
|
||||||
drop(Box::<R>::from_raw(finalize_data.cast()));
|
drop(Box::<R>::from_raw(finalize_data.cast()));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn call_js_cb<T: 'static, V: NapiValue, R, ES>(
|
unsafe extern "C" fn call_js_cb<T: 'static, V: NapiRaw, R, ES>(
|
||||||
raw_env: sys::napi_env,
|
raw_env: sys::napi_env,
|
||||||
js_callback: sys::napi_value,
|
js_callback: sys::napi_value,
|
||||||
context: *mut c_void,
|
context: *mut c_void,
|
||||||
|
|
Loading…
Reference in a new issue