Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvalencik committed Sep 5, 2024
1 parent d8d93cf commit 5b25579
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions crates/neon/src/event/channel.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::{
error, fmt, mem,
error, fmt,
sync::{
atomic::{AtomicUsize, Ordering},
Arc,
},
};

use crate::{
context::{Context, Cx},
context::{internal::Env, Context, Cx},
result::{NeonResult, ResultExt, Throw},
sys::{raw::Env, tsfn::ThreadsafeFunction},
sys::{self, tsfn::ThreadsafeFunction},
};

#[cfg(feature = "futures")]
Expand Down Expand Up @@ -44,7 +44,7 @@ mod oneshot {
}
}

type Callback = Box<dyn FnOnce(Env) + Send + 'static>;
type Callback = Box<dyn FnOnce(sys::Env) + Send + 'static>;

/// Channel for scheduling Rust closures to execute on the JavaScript main thread.
///
Expand Down Expand Up @@ -159,7 +159,7 @@ impl Channel {
{
let (tx, rx) = oneshot::channel();
let callback = Box::new(move |env| {
let env = unsafe { mem::transmute(env) };
let env = Env::from(env);

// Note: It is sufficient to use `Cx` because
// N-API creates a `HandleScope` before calling the callback.
Expand Down Expand Up @@ -409,7 +409,7 @@ impl ChannelState {
}

// Monomorphized trampoline funciton for calling the user provided closure
fn callback(env: Option<Env>, callback: Callback) {
fn callback(env: Option<sys::Env>, callback: Callback) {
if let Some(env) = env {
callback(env);
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/handle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'a, F: Value, T: Value> ResultExt<Handle<'a, T>> for DowncastResult<'a, F,
fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, T> {
match self {
Ok(v) => Ok(v),
Err(e) => cx.throw_type_error(&e.to_string()),
Err(e) => cx.throw_type_error(e.to_string()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/types_impl/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl<T: Finalize + 'static> JsBox<T> {
// contained value `T`.
fn finalizer<U: Finalize + 'static>(env: raw::Env, data: BoxAny) {
let data = *data.downcast::<U>().unwrap();
let env = unsafe { std::mem::transmute(env) };
let env = Env::from(env);

Cx::with_context(env, move |mut cx| data.finalize(&mut cx));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/types_impl/extract/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn json_stringify<'cx>(cx: &mut Cx<'cx>) -> JsResult<'cx, JsFunction> {
.map(|f| f.to_inner(cx))
}

fn stringify<'cx>(cx: &mut Cx<'cx>, v: Handle<JsValue>) -> NeonResult<String> {
fn stringify(cx: &mut Cx, v: Handle<JsValue>) -> NeonResult<String> {
json_stringify(cx)?
.call(cx, v, [v])?
.downcast_or_throw::<JsString, _>(cx)
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/types_impl/extract/try_from_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl<'cx> TryFromJs<'cx> for ArrayBuffer {
from_js!();
}

fn is_null_or_undefined<'cx, V>(cx: &mut Cx<'cx>, v: Handle<V>) -> NeonResult<bool>
fn is_null_or_undefined<V>(cx: &mut Cx, v: Handle<V>) -> NeonResult<bool>
where
V: Value,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/types_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl<'a> ResultExt<Handle<'a, JsString>> for StringResult<'a> {
fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, JsString> {
match self {
Ok(v) => Ok(v),
Err(e) => cx.throw_range_error(&e.to_string()),
Err(e) => cx.throw_range_error(e.to_string()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/types_impl/utf8.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;

const SMALL_MAX: usize = std::i32::MAX as usize;
const SMALL_MAX: usize = i32::MAX as usize;

/// V8 APIs that take UTF-8 strings take their length in the form of 32-bit
/// signed integers. This type represents a UTF-8 string that contains no
Expand Down
2 changes: 1 addition & 1 deletion test/napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,5 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
fn runtime<'a, C: Context<'a>>(cx: &mut C) -> NeonResult<&'static Runtime> {
static RUNTIME: OnceCell<Runtime> = OnceCell::new();

RUNTIME.get_or_try_init(|| Runtime::new().or_else(|err| cx.throw_error(&err.to_string())))
RUNTIME.get_or_try_init(|| Runtime::new().or_else(|err| cx.throw_error(err.to_string())))
}

0 comments on commit 5b25579

Please sign in to comment.