Skip to content

feat: replace std::time with web_time for wasm32-unknown-unknown compatibility #239

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Dicklessgreat
Copy link

@Dicklessgreat Dicklessgreat commented Jul 28, 2025

This pull request updates the reqwest-retry crate to replace the usage of std::time with the web-time crate for handling time-related functionality. This change ensures compatibility with WebAssembly (WASM) environments, where std::time is not supported. The modifications span dependency updates, source code adjustments, and test updates.

Dependency Update:

  • reqwest-retry/Cargo.toml: Added web-time = "1.1.0" as a dependency to replace std::time.

Code Changes:

  • reqwest-retry/src/middleware.rs: Replaced imports of std::time::{Duration, SystemTime} with web_time::{Duration, SystemTime} across the middleware implementation.
  • macro_rules! log_retry in reqwest-retry/src/middleware.rs: Updated example code comments to use web_time::Duration instead of std::time::Duration.

Test Updates:

  • reqwest-retry/tests/all/retry.rs:
    • Replaced std::time::Duration with web_time::Duration in multiple test functions (assert_retry_succeeds_inner, assert_retry_on_request_timeout, assert_retry_on_incomplete_message, assert_retry_on_hyper_canceled, assert_retry_on_connection_reset_by_peer). This ensures compatibility with the new dependency. [1] [2] [3] [4] [5] [6] [7]
    • Updated the RetryTimeoutResponder struct and its new method to use web_time::Duration instead of std::time::Duration.

It works on my machine

I have already tested that this fix works on my project, by refering git url and rev hash directly.
https://github.com/Dicklessgreat/reqwest-middleware/tree/refer-my-retry-policies

Draft

This PR is draft till the underlying PR is merged TrueLayer/retry-policies#29

@Dicklessgreat Dicklessgreat changed the title feat: replace std::time with web_time feat: replace std::time with web_time for wasm32-unknown-unknown compatibility Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant