ADR-402: A Duration Has the Integers’ saturating_ Arithmetic, min, max and nanos()

Status: Accepted Date: November 18, 2026 Answers: what a backoff computes on spans, which “Backoff into Nikaia” (#2118) found missing: std::time::Duration has no saturating_sub, saturating_mul or min, and no span is made from a nanosecond count Related: ADR-150 D2 (a span is made by a method on an integer, and saturates), D5 (read back in whole units) and §4 (arithmetic beyond what the type obviously has left open); ADR-368 D2 (in_nanos); Part I 2.2 (saturating_add, saturating_sub, min, max on the integers)

1. Question

use std::time

let lasted = since_first.saturating_sub(cycle_started)   // NK1171 today
let delay = first_delay.saturating_mul(1 << tries)       // NK1171 today
let wait = delay.min(ceiling)                            // NK1171 today
let jitter = offset.nanos()                              // NK1210 today

A backoff is arithmetic on spans that must not abort: a clock read twice can go back, a doubling runs past any bound. a - b with a < b panics today.

2. Decisions

D1 - A span has the integers’ saturating names.

saturating_add, saturating_sub and saturating_mul(by: int) on time::Duration, spelled and meant as Part I 2.2 spells them on an integer: saturating_sub below zero is no time at all, saturating_add and saturating_mul past the longest span stay at the longest span (ADR-150 D2’s rule for the constructors). A negative factor is no time at all, as a negative count is. Plain + - * keep the checked meaning they have, as on an integer: a span that would go below zero or past the longest one panics.

D2 - A span has min and max.

a.min(b) and a.max(b), as on an integer. Spans already compare with < <= > >=; these are the two names Part I gives every integer for it.

D3 - nanos() is the sixth constructor.

n.nanos() beside micros, millis, seconds, minutes, hours, on both integer types and under ADR-150 D2’s rules (below zero is no time). It mirrors ADR-368 D2’s in_nanos, so the unit has a name in each direction, which is ADR-150 D5’s rule.

3. Consequences

4. What this does not decide

This site is open source. Improve this page.