style: clippy fix
This commit is contained in:
parent
968d9e10b1
commit
6e4b16fe5d
9 changed files with 15 additions and 26 deletions
|
@ -52,7 +52,7 @@ impl FromNapiValue for BigInt {
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
let mut words: Vec<u64> = Vec::with_capacity(word_count as usize);
|
let mut words: Vec<u64> = Vec::with_capacity(word_count);
|
||||||
let mut sign_bit = 0;
|
let mut sign_bit = 0;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -64,7 +64,7 @@ impl FromNapiValue for BigInt {
|
||||||
words.as_mut_ptr(),
|
words.as_mut_ptr(),
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
words.set_len(word_count as usize);
|
words.set_len(word_count);
|
||||||
}
|
}
|
||||||
if word_count == 0 {
|
if word_count == 0 {
|
||||||
words = vec![0];
|
words = vec![0];
|
||||||
|
@ -155,7 +155,7 @@ impl ToNapiValue for BigInt {
|
||||||
impl ToNapiValue for i128 {
|
impl ToNapiValue for i128 {
|
||||||
unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> crate::Result<sys::napi_value> {
|
unsafe fn to_napi_value(env: sys::napi_env, val: Self) -> crate::Result<sys::napi_value> {
|
||||||
let mut raw_value = ptr::null_mut();
|
let mut raw_value = ptr::null_mut();
|
||||||
let sign_bit = if val > 0 { 0 } else { 1 };
|
let sign_bit = i32::from(val <= 0);
|
||||||
let words = &val as *const i128 as *const u64;
|
let words = &val as *const i128 as *const u64;
|
||||||
check_status!(unsafe {
|
check_status!(unsafe {
|
||||||
sys::napi_create_bigint_words(env, sign_bit, 2, words, &mut raw_value)
|
sys::napi_create_bigint_words(env, sign_bit, 2, words, &mut raw_value)
|
||||||
|
|
|
@ -66,6 +66,7 @@ impl<T> Drop for Reference<T> {
|
||||||
|
|
||||||
impl<T: 'static> Reference<T> {
|
impl<T: 'static> Reference<T> {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
||||||
pub fn add_ref(env: crate::sys::napi_env, t: *mut c_void, value: RefInformation) {
|
pub fn add_ref(env: crate::sys::napi_env, t: *mut c_void, value: RefInformation) {
|
||||||
REFERENCE_MAP.borrow_mut(|map| {
|
REFERENCE_MAP.borrow_mut(|map| {
|
||||||
if let Some((_, previous_ref, previous_rc)) = map.insert(t, value) {
|
if let Some((_, previous_ref, previous_rc)) = map.insert(t, value) {
|
||||||
|
|
|
@ -115,7 +115,7 @@ impl Env {
|
||||||
#[cfg(feature = "napi6")]
|
#[cfg(feature = "napi6")]
|
||||||
pub fn create_bigint_from_i128(&self, value: i128) -> Result<JsBigInt> {
|
pub fn create_bigint_from_i128(&self, value: i128) -> Result<JsBigInt> {
|
||||||
let mut raw_value = ptr::null_mut();
|
let mut raw_value = ptr::null_mut();
|
||||||
let sign_bit = if value > 0 { 0 } else { 1 };
|
let sign_bit = i32::from(value <= 0);
|
||||||
let words = &value as *const i128 as *const u64;
|
let words = &value as *const i128 as *const u64;
|
||||||
check_status!(unsafe {
|
check_status!(unsafe {
|
||||||
sys::napi_create_bigint_words(self.0, sign_bit, 2, words, &mut raw_value)
|
sys::napi_create_bigint_words(self.0, sign_bit, 2, words, &mut raw_value)
|
||||||
|
|
|
@ -204,7 +204,7 @@ impl TryFrom<JsBigInt> for u64 {
|
||||||
impl JsBigInt {
|
impl JsBigInt {
|
||||||
/// <https://nodejs.org/api/n-api.html#n_api_napi_get_value_bigint_words>
|
/// <https://nodejs.org/api/n-api.html#n_api_napi_get_value_bigint_words>
|
||||||
pub fn get_words(&mut self) -> Result<(bool, Vec<u64>)> {
|
pub fn get_words(&mut self) -> Result<(bool, Vec<u64>)> {
|
||||||
let mut words: Vec<u64> = Vec::with_capacity(self.word_count as usize);
|
let mut words: Vec<u64> = Vec::with_capacity(self.word_count);
|
||||||
let word_count = &mut self.word_count;
|
let word_count = &mut self.word_count;
|
||||||
let mut sign_bit = 0;
|
let mut sign_bit = 0;
|
||||||
check_status!(unsafe {
|
check_status!(unsafe {
|
||||||
|
@ -218,7 +218,7 @@ impl JsBigInt {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
words.set_len(self.word_count as usize);
|
words.set_len(self.word_count);
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((sign_bit == 1, words))
|
Ok((sign_bit == 1, words))
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl JsString {
|
||||||
check_status!(unsafe {
|
check_status!(unsafe {
|
||||||
sys::napi_get_value_string_utf8(self.0.env, self.0.value, ptr::null_mut(), 0, &mut length)
|
sys::napi_get_value_string_utf8(self.0.env, self.0.value, ptr::null_mut(), 0, &mut length)
|
||||||
})?;
|
})?;
|
||||||
Ok(length as usize)
|
Ok(length)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn utf16_len(&self) -> Result<usize> {
|
pub fn utf16_len(&self) -> Result<usize> {
|
||||||
|
@ -43,7 +43,7 @@ impl JsString {
|
||||||
check_status!(unsafe {
|
check_status!(unsafe {
|
||||||
sys::napi_get_value_string_utf16(self.0.env, self.0.value, ptr::null_mut(), 0, &mut length)
|
sys::napi_get_value_string_utf16(self.0.env, self.0.value, ptr::null_mut(), 0, &mut length)
|
||||||
})?;
|
})?;
|
||||||
Ok(length as usize)
|
Ok(length)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn latin1_len(&self) -> Result<usize> {
|
pub fn latin1_len(&self) -> Result<usize> {
|
||||||
|
@ -51,7 +51,7 @@ impl JsString {
|
||||||
check_status!(unsafe {
|
check_status!(unsafe {
|
||||||
sys::napi_get_value_string_latin1(self.0.env, self.0.value, ptr::null_mut(), 0, &mut length)
|
sys::napi_get_value_string_latin1(self.0.env, self.0.value, ptr::null_mut(), 0, &mut length)
|
||||||
})?;
|
})?;
|
||||||
Ok(length as usize)
|
Ok(length)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_utf8(self) -> Result<JsStringUtf8> {
|
pub fn into_utf8(self) -> Result<JsStringUtf8> {
|
||||||
|
|
|
@ -87,7 +87,7 @@ fn test_delete_named_property(ctx: CallContext) -> Result<JsBoolean> {
|
||||||
fn test_get_property(ctx: CallContext) -> Result<JsUnknown> {
|
fn test_get_property(ctx: CallContext) -> Result<JsUnknown> {
|
||||||
let obj = ctx.get::<JsObject>(0)?;
|
let obj = ctx.get::<JsObject>(0)?;
|
||||||
let key = ctx.get::<JsUnknown>(1)?;
|
let key = ctx.get::<JsUnknown>(1)?;
|
||||||
obj.get_property(&key)
|
obj.get_property(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[js_function(1)]
|
#[js_function(1)]
|
||||||
|
|
|
@ -22,13 +22,7 @@ fn either3(input: Either3<String, u32, bool>) -> u32 {
|
||||||
match input {
|
match input {
|
||||||
Either3::A(s) => s.len() as u32,
|
Either3::A(s) => s.len() as u32,
|
||||||
Either3::B(n) => n,
|
Either3::B(n) => n,
|
||||||
Either3::C(b) => {
|
Either3::C(b) => u32::from(b),
|
||||||
if b {
|
|
||||||
1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,13 +36,7 @@ fn either4(input: Either4<String, u32, bool, Obj>) -> u32 {
|
||||||
match input {
|
match input {
|
||||||
Either4::A(s) => s.len() as u32,
|
Either4::A(s) => s.len() as u32,
|
||||||
Either4::B(n) => n,
|
Either4::B(n) => n,
|
||||||
Either4::C(b) => {
|
Either4::C(b) => u32::from(b),
|
||||||
if b {
|
|
||||||
1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Either4::D(f) => match f.v {
|
Either4::D(f) => match f.v {
|
||||||
Either::A(s) => s.len() as u32,
|
Either::A(s) => s.len() as u32,
|
||||||
Either::B(n) => n,
|
Either::B(n) => n,
|
||||||
|
|
|
@ -69,5 +69,5 @@ impl Task for AsyncBuffer {
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
fn async_reduce_buffer(buf: Buffer) -> Result<AsyncTask<AsyncBuffer>> {
|
fn async_reduce_buffer(buf: Buffer) -> Result<AsyncTask<AsyncBuffer>> {
|
||||||
Ok(AsyncTask::new(AsyncBuffer { buf: buf.clone() }))
|
Ok(AsyncTask::new(AsyncBuffer { buf }))
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ pub fn test_async(env: Env) -> napi::Result<napi::JsObject> {
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
pub fn from_js(env: Env, input_object: Object) -> napi::Result<String> {
|
pub fn from_js(env: Env, input_object: Object) -> napi::Result<String> {
|
||||||
let a: Welcome = env.from_js_value(&input_object)?;
|
let a: Welcome = env.from_js_value(input_object)?;
|
||||||
Ok(serde_json::to_string(&a)?)
|
Ok(serde_json::to_string(&a)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue