Split Promise<primitive> into raw extern + async wrapper#11
Closed
connyay wants to merge 1 commit into
Closed
Conversation
Methods returning Promise<boolean | string | number> now emit a synchronous Promise-returning extern plus an inherent-impl async fn that awaits and casts the resolved JsValue. The public signature (pub async fn -> Result<T, JsValue>) is unchanged. Why: some wasm-bindgen flavours (notably the workers-rs fork) tightened Promise<T> / JsFuture<T> to require T: JsGeneric, which Rust primitives don't impl, so a direct `pub async fn -> Result<bool, JsValue>` extern fails to compile under those flavours. Routing through js_sys::Promise (no JsGeneric bound) avoids the constraint, and the JsValue::as_* cast happens once in the wrapper instead of at every call site. Custom @throws error types still go through the existing From<JsValue> for CustomError contract via a trailing .into().
Contributor
|
This is the unfortunate aspect of using erasable generics - So rather I think the fix we need here is the conversion of the type to the canonical JS type instead of the Rust primitive on the async generics. |
Contributor
Author
|
closing in favor of #14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Methods returning Promise<boolean | string | number> now emit a synchronous Promise-returning extern plus an inherent-impl async fn that awaits and casts the resolved JsValue. The public signature (pub async fn -> Result<T, JsValue>) is unchanged.
Why: some wasm-bindgen flavours (notably the workers-rs fork) tightened Promise / JsFuture to require T: JsGeneric, which Rust primitives don't impl, so a direct
pub async fn -> Result<bool, JsValue>extern fails to compile under those flavours. Routing through js_sys::Promise (no JsGeneric bound) avoids the constraint, and the JsValue::as_* cast happens once in the wrapper instead of at every call site. Custom @throws error types still go through the existingFrom for CustomError contract via a trailing .into().