mirror of
https://github.com/napi-rs/napi-rs.git
synced 2025-12-08 19:56:07 +00:00
chore(napi): remove Read from Uint8Array (#2346)
This commit is contained in:
parent
f2377e2d70
commit
ae8eab3ef8
@ -1,5 +1,4 @@
|
||||
use std::ffi::c_void;
|
||||
use std::io::{self, Read};
|
||||
use std::mem;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::ptr;
|
||||
@ -33,8 +32,6 @@ trait Finalizer {
|
||||
|
||||
fn data_managed_type(&self) -> &DataManagedType;
|
||||
|
||||
fn len(&self) -> &usize;
|
||||
|
||||
fn ref_count(&self) -> usize;
|
||||
}
|
||||
|
||||
@ -68,10 +65,6 @@ macro_rules! impl_typed_array {
|
||||
&self.data_managed_type
|
||||
}
|
||||
|
||||
fn len(&self) -> &usize {
|
||||
&self.length
|
||||
}
|
||||
|
||||
fn ref_count(&self) -> usize {
|
||||
Arc::strong_count(&self.drop_in_vm)
|
||||
}
|
||||
@ -604,14 +597,14 @@ macro_rules! impl_from_slice {
|
||||
};
|
||||
}
|
||||
|
||||
unsafe extern "C" fn finalizer<Data, T: Finalizer<RustType = Data>>(
|
||||
unsafe extern "C" fn finalizer<Data, T: Finalizer<RustType = Data> + AsRef<[Data]>>(
|
||||
_env: sys::napi_env,
|
||||
finalize_data: *mut c_void,
|
||||
finalize_hint: *mut c_void,
|
||||
) {
|
||||
let data = unsafe { *Box::from_raw(finalize_hint as *mut T) };
|
||||
let data_managed_type = *data.data_managed_type();
|
||||
let length = *data.len();
|
||||
let length = data.as_ref().len();
|
||||
match data_managed_type {
|
||||
DataManagedType::Vm => {
|
||||
// do nothing
|
||||
@ -686,13 +679,6 @@ impl Uint8Array {
|
||||
}
|
||||
}
|
||||
|
||||
impl Read for Uint8Array {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
let mut inner: &[u8] = &*self;
|
||||
Read::read(&mut inner, buf)
|
||||
}
|
||||
}
|
||||
|
||||
/// Zero copy Uint8ClampedArray slice shared between Rust and Node.js.
|
||||
/// It can only be used in non-async context and the lifetime is bound to the fn closure.
|
||||
/// If you want to use Node.js `Uint8ClampedArray` in async context or want to extend the lifetime, use `Uint8ClampedArray` instead.
|
||||
|
||||
@ -28,9 +28,15 @@ impl<T: NapiRaw> Ref<T> {
|
||||
}
|
||||
|
||||
pub fn unref(&mut self, env: &Env) -> Result<()> {
|
||||
check_status!(unsafe { sys::napi_reference_unref(env.0, self.raw_ref, &mut 0) })?;
|
||||
check_status!(
|
||||
unsafe { sys::napi_reference_unref(env.0, self.raw_ref, &mut 0) },
|
||||
"unref Ref failed"
|
||||
)?;
|
||||
|
||||
check_status!(unsafe { sys::napi_delete_reference(env.0, self.raw_ref) })?;
|
||||
check_status!(
|
||||
unsafe { sys::napi_delete_reference(env.0, self.raw_ref) },
|
||||
"delete Ref failed"
|
||||
)?;
|
||||
self.taken = true;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user