Wasm compatibility #29
Open
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.
This pull request introduces compatibility with the
wasm32-unknown-unknowntarget and replaces the standard library's time utilities with theweb_timecrate to improve cross-platform support. The changes also include updates to dependencies and documentation to reflect these enhancements.Motivation
I am using
dioxusandreqwestto send requests from the frontend to the backend. To enhance the client functionality, I needed to usereqwest-middlewareandreqwest-retry. However, when trying this in a WASM environment, I encountered a runtime panic. Message below is from the browser’s developer tools:This panic occurs because this crates use
std::time::{Duration, SystemTime}, which are not supported inwasm32-unknown-unknown.To resolve this, I replaced those with the
web_timecrate.Compatibility with
wasm32-unknown-unknowntarget:.cargo/config.toml: Addedrustflagsconfiguration for thewasm32-unknown-unknowntarget to specify thegetrandom_backend="wasm_js"feature. Please refer getrandom doc to see why this config is necessary(for checking if this crate is buildable onwasm32-unknown-unknownbycargo build --features=wasm --target=wasm32-unknown-unknown)Cargo.toml: Added new dependencies (web-time,getrandom) and defined awasmfeature for compatibility with thewasm32-unknown-unknowntarget.Transition to
web_timecrate:src/policies/exponential_backoff.rs: Replacedstd::time::{Duration, SystemTime}withweb_time::{Duration, SystemTime}across the file, including examples and implementations. [1] [2] [3] [4] [5]src/retry_policy.rs: Updated imports to useweb_time::{Duration, SystemTime}instead of the standard library equivalents. [1] [2]Documentation updates:
CHANGELOG.md: Added a note about compatibility withwasm32-unknown-unknownin the changelog under the "Added" section.