Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neon: Remove JsResultExt #904

Merged
merged 2 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/neon/src/handle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub use self::root::Root;
use crate::{
context::{internal::Env, Context},
handle::internal::{SuperType, TransparentNoCopyWrapper},
result::{JsResult, JsResultExt},
result::{JsResult, ResultExt},
sys::{self, raw},
types::Value,
};
Expand Down Expand Up @@ -138,7 +138,7 @@ impl<F: Value, T: Value> Error for DowncastError<F, T> {}
/// The result of a call to [`Handle::downcast()`](Handle::downcast).
pub type DowncastResult<'a, F, T> = Result<Handle<'a, T>, DowncastError<F, T>>;

impl<'a, F: Value, T: Value> JsResultExt<'a, T> for DowncastResult<'a, F, T> {
impl<'a, F: Value, T: Value> ResultExt<Handle<'a, T>> for DowncastResult<'a, F, T> {
fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, T> {
match self {
Ok(v) => Ok(v),
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use crate::{
},
handle::{Handle, Root},
object::Object,
result::{JsResult, JsResultExt, NeonResult, ResultExt as NeonResultExt},
result::{JsResult, NeonResult, ResultExt as NeonResultExt},
types::{
boxed::{Finalize, JsBox},
JsArray, JsArrayBuffer, JsBoolean, JsBuffer, JsError, JsFunction, JsNull, JsNumber,
Expand Down
8 changes: 1 addition & 7 deletions crates/neon/src/result/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use std::{
marker::PhantomData,
};

use crate::{context::Context, handle::Handle, types::Value};
use crate::{context::Context, handle::Handle};

/// A [unit type][unit] indicating that the JavaScript thread is throwing an exception.
///
Expand Down Expand Up @@ -69,12 +69,6 @@ pub type NeonResult<T> = Result<T, Throw>;
/// Shorthand for a [`NeonResult`](NeonResult) that produces JavaScript values.
pub type JsResult<'b, T> = NeonResult<Handle<'b, T>>;

/// Extension trait for converting Rust [`Result`](std::result::Result) values
/// into [`JsResult`](JsResult) values by throwing JavaScript exceptions.
pub trait JsResultExt<'a, V: Value> {
fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, V>;
}

/// Extension trait for converting Rust [`Result`](std::result::Result) values
/// into [`NeonResult`](NeonResult) values by throwing JavaScript exceptions.
pub trait ResultExt<T> {
Expand Down
4 changes: 2 additions & 2 deletions crates/neon/src/sys/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ macro_rules! napi_name {
///
/// Sample input:
///
/// ```
/// ```ignore
/// extern "C" {
/// fn get_undefined(env: Env, result: *mut Value) -> Status;
/// /* Additional functions may be included */
Expand All @@ -46,7 +46,7 @@ macro_rules! napi_name {
///
/// Generated output:
///
/// ```
/// ```ignore
/// // Each field is a pointer to a N-API function
/// struct Napi {
/// get_undefined: unsafe extern "C" fn(env: Env, result: *mut Value) -> Status,
Expand Down
4 changes: 2 additions & 2 deletions crates/neon/src/types/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
context::{internal::Env, Context},
handle::{internal::TransparentNoCopyWrapper, Handle, Managed},
object::Object,
result::{JsResult, JsResultExt},
result::{JsResult, ResultExt},
sys::{self, raw},
};

Expand Down Expand Up @@ -75,7 +75,7 @@ impl DateErrorKind {
}
}

impl<'a, T: Value> JsResultExt<'a, T> for Result<Handle<'a, T>, DateError> {
impl<'a, T: Value> ResultExt<Handle<'a, T>> for Result<Handle<'a, T>, DateError> {
/// Creates an `Error` on error
fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, T> {
self.or_else(|e| cx.throw_range_error(e.0.as_str()))
Expand Down
4 changes: 2 additions & 2 deletions crates/neon/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ use crate::{
Handle, Managed,
},
object::{Object, This},
result::{JsResult, JsResultExt, NeonResult, Throw},
result::{JsResult, NeonResult, ResultExt, Throw},
sys::{self, raw},
types::{
function::{CallOptions, ConstructOptions},
Expand Down Expand Up @@ -388,7 +388,7 @@ impl fmt::Display for StringOverflow {
/// The result of constructing a new `JsString`.
pub type StringResult<'a> = Result<Handle<'a, JsString>, StringOverflow>;

impl<'a> JsResultExt<'a, JsString> for StringResult<'a> {
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),
Expand Down