| Crates.io | saturating-time |
| lib.rs | saturating-time |
| version | 0.3.0 |
| created_at | 2025-11-18 22:31:05.816706+00 |
| updated_at | 2025-11-25 17:05:41.567316+00 |
| description | A trait for limits and saturations on types inside std::time |
| homepage | |
| repository | https://codeberg.org/cve/saturating-time |
| max_upload_size | |
| id | 1939090 |
| size | 33,918 |
saturating-timeA trait for limits and saturations on types inside [std::time].
saturating-time only adds a single trait, [SaturatingTime] that
is implemented for various types from the standard library.SaturatingTime::saturating_add()] and
[SaturatingTime::saturating_sub()] become a part of the standard library,
developers would only have to remove the use saturating_time::SaturatingTime
line from their code.1 2.unsafe Rust code.saturating-time is a very minimal crate that only exposes a minimal trait:
[SaturatingTime].
The trait itself offers the following methods:
SaturatingTime::max_value()] – Returns the maximum value for this type.SaturatingTime::min_value()] – Returns the minimum value for this type.SaturatingTime::saturating_add()] – Saturating addition for this type.SaturatingTime::saturating_sub()] – Saturating subtraction for this type.SaturatingTime::saturating_duration_since()] - Saturating time deltas for this type.This trait is sealed, meaning applications may not implement it themselves. However, this crate implements this trait for two structures:
std::time::Instant]std::time::SystemTime]Add the following to your Cargo.toml:
[dependencies]
saturating-time = "0.3.0"
Now, you can use saturating-time in your code:
use std::time::{Duration, SystemTime};
use saturating_time::SaturatingTime;
// Get the maximum and minimum.
let max = SystemTime::max_value();
let min = SystemTime::min_value();
assert_eq!(max.saturating_add(Duration::new(1, 0)), max);
assert_eq!(min.saturating_sub(Duration::new(1, 0)), min);
assert!(max.saturating_duration_since(SystemTime::UNIX_EPOCH) >= Duration::ZERO);
The eventual goal is to get this functionality into the Rust standard library.
SystemTimeSystemTime::MIN and SystemTime::MAXThere is an ACP that has been approved in November 2025.3 Please follow the tracking issue4 for more information about this in particular.
SystemTime::saturating_add() and SystemTime::saturating_sub()None yet.
InstantNone yet.
This crate is licensed under MIT OR Apache-2.0.
See the respective LICENSE-* files in the repository for more information.