-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Replace TryFrom with custom TryFromJsValue trait #3709
Replace TryFrom with custom TryFromJsValue trait #3709
Conversation
0afb3ed
to
a3aad01
Compare
a3aad01
to
50f52e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add an entry to the changelog as well?
LGTM otherwise.
@hamza1311 and @Liamolucko, the idea here is to yank the current version and release a new one with this change. Let me know what you think. |
I feel the same way. This does un-fix #2231 though, since The easy solution is just to move it to |
convert module is public, it already exports From/IntoWasmAbi, and others. But these two look like custom |
Yes, it's technically public, but see its documentation:
It's only really public so that macros can access it, nobody should be using anything from in there directly. |
Oh. I see. Your suggestion is to move the trait to wasm_bindgen - root module? |
done |
26b469c
to
135407a
Compare
Even if we want to do that one day, it would still require |
I'm on the fence about moving |
This commit replaces the usage of the standard library's TryFrom trait with a custom TryFromJsValue trait added for handling the conversion from JavaScript values in WASM. This trait has been implemented for different types across multiple modules to ensure consistent error handling on failed conversions. fixes rustwasm#3685
In this commit, the TryFromJsValue trait has been relocated from the convert::traits module to the root module. Subsequently, all the references to TryFromJsValue have been updated across various modules. This reorganization helps in improving the coherence and organization of the codebase relative to JavaScript-to-WASM conversions.
The updated CHANGELOG reflects the recent bug fix in wasm-bindgen. It used to force auto-derivation of the TryFrom trait for any struct, but now it will respect the use of custom TryFrom<JsValue> implementations by adopting the new TryFromJsValue trait instead.
Co-authored-by: daxpedda <daxpedda@gmail.com>
1007bb1
to
ba58bf4
Compare
This refactor brings the TryFromJsValue trait into the convert sub-module, from the core library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just some nits about docs.
As mentioned before, this unfixes #2231, but we can figure out exactly what to do here at some later point.
@biryukovmaxim you should probably hold off on any major changes for now, we are still discussing how exactly to proceed, there's no need to move TryFromJsValue
back and forth upon every whimsical comment I make! (don't move it back now 😄)
Co-authored-by: daxpedda <daxpedda@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to move forward with this, we can figure out how to fix #2231 again in the future.
I've hit a problem with the TryFrom changes that is unrelated to #3685, but that would probably also occur with this PR, related to the ambiguity of using
The way to solve that would be to use the fully qualified syntax for fn try_from_js_value(value: #wasm_bindgen::JsValue)
- -> #wasm_bindgen::__rt::std::result::Result<Self, Self::Error> {
+ -> #wasm_bindgen::__rt::std::result::Result<Self, <Self as TryFromJsValue>::Error> { I can open a PR myself after this one is merged if you prefer to merge this one as-is though. |
Could you open a PR targeting |
I think this was already fixed in #3678, can you check if it still happens using a git version of the |
My bad, seems this was fixed on master a bit ago, and I was looking at the struct changes of this PR instead of the enum changes. I just tested both master and this PR and they both work as expected, sorry for the confusion! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like regressing on #2231, but I guess the breaking changes are a higher priority.
By the way, what I meant by a |
I'm gonna go ahead and merge this now and get the new release going. |
This commit replaces the usage of the standard library's TryFrom trait with a custom TryFromJsValue trait added for handling the conversion from JavaScript values in WASM. This trait has been implemented for different types across multiple modules to ensure consistent error handling on failed conversions.
fixes #3685