Log inSign up
Log inSign up
rustbites
291 posts
@rustbites

rustbites

@rustbites
Random bite-sized Rust tips. Collection of notes of one curious developer on his journey to learn Rust.
rustbites.com
Joined September 2020
19 Following
37 Followers
RepliesRepliesRepostsRepostsMediaMedia

rustbites’s posts

Log in or sign up for X

See what’s happening and join the conversation

Continue with phone
or
Log in with username or email
Terms·Privacy·Cookies·Accessibility·Ads Info·© 2026 X Corp.
  • @rustbites
    rustbites
    @rustbites
    Aug 13
    You computed deadline - Instant::now() for a retry timeout. The deadline passed — and Rust silently returned zero. No panic, no Err, just a 0s budget some APIs read as "wait forever". checked_duration_since returns None when time's up. Impossible to miss. #rustlang
    Image
    View media
  • @rustbites
    rustbites
    @rustbites
    Aug 13
    NTP stepped the clock back, and your SystemTime .elapsed().unwrap() panicked at 2am. The Err isn't noise — it tells you how far the clock jumped. And for timing work, use Instant: monotonic, no Result, never goes backwards. #rustlang
    Image
    View media
  • @rustbites
    rustbites
    @rustbites
    Aug 12
    Your backoff needs delay * 1.5, but Duration only multiplies by integers — so you tear it apart into an f64 and rebuild it just to scale a timeout. Duration::mul_f64 (and div_f64) do it in one call, nanosecond precision kept. #rustlang
    Image
    View media
  • @rustbites
    rustbites
    @rustbites
    Aug 12
    Your progress bar is stuck at 0% and the math looks fine. as_secs() / as_secs() is integer division — 1.5s of 60s truncates to zero. div_duration_f64 gives the real ratio: 0.025, sub-second precision included. Stable since Rust 1.80. #rustlang
    Image
    View media
  • @rustbites
    rustbites
    @rustbites
    Aug 11
    Your timeout budget passed every test. Then one slow call made elapsed > budget, and budget - elapsed panicked: overflow when subtracting durations. checked_sub returns None; saturating_sub clamps to ZERO. A blown budget becomes a value, not a crash. #rustlang
    Image
    View media