atomic-time 1.0.0 — atomic Duration, SystemTime, and Instant types for Rust
Hi r/rust,
I’ve released atomic-time 1.0.0, a crate providing thread-safe atomic versions of Rust’s time types:
- AtomicDuration
- AtomicOptionDuration
- AtomicSystemTime
- AtomicOptionSystemTime
- AtomicInstant
- AtomicOptionInstant
The types are built on portable-atomic::AtomicU128. Operations are lock-free on targets with native 128-bit atomics; otherwise, portable-atomic may use its fallback implementation. The crate itself forbids unsafe code.
The API follows the standard atomic types where applicable:
- load, store, and swap
- compare_exchange / compare_exchange_weak
- fetch_update, try_update, and update
- fetch_min / fetch_max
- Saturating fetch addition and subtraction for the Duration types
use atomic_time::AtomicDuration;
use std::sync::atomic::Ordering;
use std::time::Duration;
let timeout = AtomicDuration::new(Duration::from_secs(30));
let previous = timeout.fetch_saturating_add(
Duration::from_secs(5),
Ordering::AcqRel,
);
assert_eq!(previous, Duration::from_secs(30));
assert_eq!(
timeout.load(Ordering::Acquire),
Duration::from_secs(35),
);
AtomicDuration and AtomicOptionDuration support no_std. Optional integrations are available for serde, arbitrary, quickcheck, and proptest.
A couple of deliberate constraints:
- SystemTime values must be at or after UNIX_EPOCH.
- Instant values use a process-local baseline, so their encoded form should not be persisted as a durable deadline.
- Property-testing integrations intentionally exclude the Instant types because generated values would not be deterministic across process runs.
The 1.0 release stabilizes the public API and wire format, which remains compatible with values encoded by 0.2.1. The MSRV is Rust 1.85.
Links:
- crates.io
- Documentation
- GitHub
- 1.0.0 release notes
Feedback, API suggestions, and platform reports are very welcome.
9 points · 2 comments
Mentions
atomic-time 1.0.0 — atomic Duration, SystemTime, and Instant types for Rust Hi r/rust, I’ve released atomic-time 1.0.0, a crate providing thread-safe atomic versions of Rust’s time types: - AtomicDuration - AtomicOptionDuration - AtomicSystemTime - AtomicOptionSystemTime - AtomicInstant - AtomicOptionInstant The types are built on portable-atomic::AtomicU128. Operations are lock-free on targets with native 128-bit atomics; otherwise, portable-atomic may use its fallback implementation. The crate itself forbids unsafe code. The API follows the standard atomic types where applicable: - load, store, and swap - compare_exchange / compare_exchange_weak - fetch_update, try_update, and update - fetch_min / fetch_max - Saturating fetch addition and subtraction for the Duration types use atomic_time::AtomicDuration; use std::sync::atomic::Ordering; use std::time::Duration; let timeout = AtomicDuration::new(Duration::from_secs(30)); let previous = timeout.fetch_saturating_add( Duration::from_secs(5), Ordering::AcqRel, ); assert_eq!(previous, Duration::from_secs(30)); assert_eq!( timeout.load(Ordering::Acquire), Duration::from_secs(35), ); AtomicDuration and AtomicOptionDuration support no_std. Optional integrations are available for serde, arbitrary, quickcheck, and proptest. A couple of deliberate constraints: - SystemTime values must be at or after UNIX_EPOCH. - Instant values use a process-local baseline, so their encoded form should not be persisted as a durable deadline. - Property-testing integrations intentionally exclude the Instant types because generated values would not be deterministic across process runs. The 1.0 release stabilizes the public API and wire format, which remains compatible with values encoded by 0.2.1. The MSRV is Rust 1.85. Links: - crates.io - Documentation - GitHub - 1.0.0 release notes Feedback, API suggestions, and platform reports are very welcome.