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

Allow returning Result<*mut T, _> and Result<*const T, _> from async functions #3059

Merged
merged 2 commits into from
Nov 21, 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/macro/ui-tests/async-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ error[E0277]: the trait bound `wasm_bindgen::JsValue: From<BadType>` is not sati
<wasm_bindgen::JsValue as From<&'a String>>
<wasm_bindgen::JsValue as From<&'a T>>
<wasm_bindgen::JsValue as From<&'a str>>
<wasm_bindgen::JsValue as From<JsError>>
and 73 others
<wasm_bindgen::JsValue as From<*const T>>
and 75 others
= note: required because of the requirements on the impl of `Into<wasm_bindgen::JsValue>` for `BadType`
= note: required because of the requirements on the impl of `IntoJsResult` for `BadType`
note: required by `into_js_result`
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,20 @@ impl<'a> From<&'a str> for JsValue {
}
}

impl<T> From<*mut T> for JsValue {
#[inline]
fn from(s: *mut T) -> JsValue {
JsValue::from(s as usize)
}
}
Comment on lines +788 to +793
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be implemented for *const T as well.


impl<T> From<*const T> for JsValue {
#[inline]
fn from(s: *const T) -> JsValue {
JsValue::from(s as usize)
}
}

if_std! {
impl<'a> From<&'a String> for JsValue {
#[inline]
Expand Down