The time crate contains two extension traits:
time::ext::NumericalStdDuration. These traits exist to make writing code involving durations (both
from the time crate and the standard library) cleaner to read. Rather than writing
Duration::seconds(5), it is possible to write
5.seconds(). It is possible to use floating point
literals such that
1.5.weeks() is equivalent to
3.days() + 12.hours().
NumericalDuration provides the following methods that return a
NumericalStdDuration provides the following methods that return a
NumericalDuration trait is implemented for
f64, such that both integer and float
literals are able to use the methods. The
NumericalStdDuration trait is implemented for
f64 for the same reasons, though the latter will perform a runtime check ensuring the value is
While it is possible to use these extension methods on non-literals, such usage is discouraged for ease of reading.