Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
morenol committed Sep 22, 2023
1 parent 161c958 commit b44bb5a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
6 changes: 2 additions & 4 deletions nj-core/src/basic.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::ptr;
use std::ffi::CString;
use std::collections::VecDeque;
use std::convert::TryFrom;

use log::error;
use log::debug;
Expand Down Expand Up @@ -287,7 +286,7 @@ impl JsEnv {
))?;

// truncate arg to actual received count
args.resize(usize::try_from(argc).unwrap(), ptr::null_mut());
args.resize(argc, ptr::null_mut());

Ok(JsCallback::new(JsEnv::new(self.0), this, args))
}
Expand Down Expand Up @@ -633,8 +632,7 @@ impl JsEnv {
&mut len
))?;

let array: &[u8] =
unsafe { slice::from_raw_parts(data as *const u8, usize::try_from(len).unwrap()) };
let array: &[u8] = unsafe { slice::from_raw_parts(data as *const u8, len) };

Ok(array)
}
Expand Down
3 changes: 1 addition & 2 deletions nj-core/src/bigint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::ptr;
use std::convert::TryFrom;

use log::trace;

Expand Down Expand Up @@ -30,7 +29,7 @@ impl<'a> JSValue<'a> for BigInt {
))?;

// Now we actually get the sign and the vector.
let mut napi_buffer: Vec<u64> = vec![0; usize::try_from(word_count).unwrap()];
let mut napi_buffer: Vec<u64> = vec![0; word_count];
let mut sign = 0;

crate::napi_call_result!(crate::sys::napi_get_value_bigint_words(
Expand Down
11 changes: 4 additions & 7 deletions nj-core/src/convert.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::convert::TryFrom;

use std::ptr;

use crate::sys::napi_value;
Expand Down Expand Up @@ -331,7 +331,7 @@ impl JSValue<'_> for String {

string_size += 1;

let chars_vec: Vec<u8> = vec![0; usize::try_from(string_size).unwrap()];
let chars_vec: Vec<u8> = vec![0; string_size];
let mut chars: Box<[u8]> = chars_vec.into_boxed_slice();
let mut read_size: usize = 0;

Expand All @@ -343,7 +343,7 @@ impl JSValue<'_> for String {
&mut read_size
))?;

let my_chars: Vec<u8> = chars[0..usize::try_from(read_size).unwrap()].into();
let my_chars: Vec<u8> = chars[0..read_size].into();

String::from_utf8(my_chars).map_err(|err| err.into())
}
Expand All @@ -365,10 +365,7 @@ impl<'a> JSValue<'a> for &'a str {
))?;

unsafe {
let i8slice = std::slice::from_raw_parts(
data as *mut ::std::os::raw::c_char,
usize::try_from(len).unwrap(),
);
let i8slice = std::slice::from_raw_parts(data as *mut ::std::os::raw::c_char, len);
let u8slice = &*(i8slice as *const _ as *const [u8]);
std::str::from_utf8(u8slice).map_err(|err| err.into())
}
Expand Down

0 comments on commit b44bb5a

Please sign in to comment.