Skip to content

Commit

Permalink
Make napi::Status #[must_use]
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvalencik committed Dec 20, 2022
1 parent c346524 commit d84bf34
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions crates/neon/src/sys/async_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub unsafe fn schedule<I, O, D>(
napi::Status::Ok => {}
status => {
// If queueing failed, delete the work to prevent a leak
napi::delete_async_work(env, *work);
let _ =napi::delete_async_work(env, *work);
assert_eq!(status, napi::Status::Ok);
}
}
Expand Down Expand Up @@ -150,7 +150,7 @@ unsafe extern "C" fn call_complete<I, O, D>(env: Env, status: napi::Status, data
..
} = *Box::<Data<I, O, D>>::from_raw(data.cast());

napi::delete_async_work(env, work);
debug_assert_eq!(napi::delete_async_work(env, work), napi::Status::Ok);

BOUNDARY.catch_failure(env, None, move |env| {
// `unwrap` is okay because `call_complete` should be called exactly once
Expand Down
1 change: 1 addition & 0 deletions crates/neon/src/sys/bindings/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub type ThreadsafeFunctionCallJs = Option<
>;

#[allow(dead_code)]
#[must_use]
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Status {
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/sys/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::{

/// Mutates the `out` argument to refer to a `napi_value` containing a newly created JavaScript Object.
pub unsafe fn new(out: &mut Local, env: Env) {
napi::create_object(env, out as *mut _);
assert_eq!(napi::create_object(env, out as *mut _), napi::Status::Ok);
}

#[cfg(feature = "napi-8")]
Expand Down
8 changes: 4 additions & 4 deletions crates/neon/src/sys/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ use super::{

/// Mutates the `out` argument provided to refer to the global `undefined` object.
pub unsafe fn undefined(out: &mut Local, env: Env) {
napi::get_undefined(env, out as *mut Local);
assert_eq!(napi::get_undefined(env, out as *mut Local), napi::Status::Ok);
}

/// Mutates the `out` argument provided to refer to the global `null` object.
pub unsafe fn null(out: &mut Local, env: Env) {
napi::get_null(env, out as *mut Local);
assert_eq!(napi::get_null(env, out as *mut Local), napi::Status::Ok);
}

/// Mutates the `out` argument provided to refer to one of the global `true` or `false` objects.
pub unsafe fn boolean(out: &mut Local, env: Env, b: bool) {
napi::get_boolean(env, b, out as *mut Local);
assert_eq!(napi::get_boolean(env, b, out as *mut Local), napi::Status::Ok);
}

/// Get the boolean value out of a `Local` object. If the `Local` object does not contain a
Expand All @@ -32,7 +32,7 @@ pub unsafe fn boolean_value(env: Env, p: Local) -> bool {
/// Mutates the `out` argument provided to refer to a newly created `Local` containing a
/// JavaScript number.
pub unsafe fn number(out: &mut Local, env: Env, v: f64) {
napi::create_double(env, v, out as *mut Local);
assert_eq!(napi::create_double(env, v, out as *mut Local), napi::Status::Ok);
}

/// Gets the underlying value of an `Local` object containing a JavaScript number. Panics if
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/sys/tsfn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl<T> Drop for ThreadsafeFunction<T> {
}

unsafe {
napi::release_threadsafe_function(
let _ = napi::release_threadsafe_function(
self.tsfn.0,
napi::ThreadsafeFunctionReleaseMode::Release,
);
Expand Down

0 comments on commit d84bf34

Please sign in to comment.