relative-duration 1.0.1

Duration with negative capabilities
Documentation
relative-duration-1.0.1 has been yanked.

relative-duration

Durations that can be negative in rust, for people that want to substract durations without having to use bigger type.

Disclaimer

This crate is still a work in progress; but I will make it more documented in the next few months since it's not so big.

if you want to use it nonetheless, here is an example of how to use it, it's pretty handy to do calculations on durations:

use std::time::Duration;
use relative_duration::RelativeDuration;

fn main() {
    let rd1 = RelativeDuration::from(Duration::from_millis(100));
    let rd2 = RelativeDuration::from(Duration::from_millis(200));
    
    let rd3 = rd1 - rd2; // Tadaaaam: negative duration, no panic !
    
    assert!(rd3.is_negative()); // It's negative
    let std_duration: Duration = rd3.into();
    
    assert_eq!(std_duration, Duration::from_millis(100)); // We can go back to standard duration, losing the sign.
}