summaryrefslogtreecommitdiff
path: root/crates/retry-error/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/retry-error/src')
-rw-r--r--crates/retry-error/src/lib.rs37
1 files changed, 35 insertions, 2 deletions
diff --git a/crates/retry-error/src/lib.rs b/crates/retry-error/src/lib.rs
index 5d00eb4aa..2ca7a9893 100644
--- a/crates/retry-error/src/lib.rs
+++ b/crates/retry-error/src/lib.rs
@@ -49,7 +49,13 @@
use std::error::Error;
use std::fmt::{self, Debug, Display, Error as FmtError, Formatter};
use std::iter;
-use std::time::{Duration, Instant, SystemTime};
+use std::time::{Duration, SystemTime};
+
+#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
+use web_time::Instant;
+
+#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
+use std::time::Instant;
/// An error type for use when we're going to do something a few times,
/// and they might all fail.
@@ -135,6 +141,7 @@ impl<E> RetryError<E> {
///
/// # Example
/// ```
+ /// # #![allow(clippy::disallowed_methods)]
/// # use retry_error::RetryError;
/// # use std::time::{Instant, SystemTime};
/// let mut retry_err: RetryError<&str> = RetryError::in_attempt_to("connect");
@@ -169,7 +176,7 @@ impl<E> RetryError<E> {
where
T: Into<E>,
{
- self.push_timed(err, Instant::now(), Some(SystemTime::now()));
+ self.push_timed(err, current_instant(), Some(current_system_time()));
}
/// Return an iterator over all of the reasons that the attempt
@@ -515,6 +522,32 @@ pub fn fmt_error_with_sources(mut e: &dyn Error, f: &mut fmt::Formatter) -> fmt:
Ok(())
}
+/// Return the current system time.
+///
+/// (This is a separate method for compatibility with wasm32.)
+#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
+fn current_system_time() -> SystemTime {
+ use web_time::web::SystemTimeExt as _;
+ web_time::SystemTime::now().to_std()
+}
+
+/// Return the current system time.
+///
+/// (This is a separate method for compatibility with wasm32.)
+#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
+fn current_system_time() -> SystemTime {
+ #![allow(clippy::disallowed_methods)]
+ SystemTime::now()
+}
+
+/// Return the current Instant.
+///
+/// (This is a separate method for compatibility with wasm32.)
+fn current_instant() -> Instant {
+ #![allow(clippy::disallowed_methods)]
+ Instant::now()
+}
+
#[cfg(test)]
mod test {
// @@ begin test lint list maintained by maint/add_warning @@