#ergonomics #wrapper #error #values #quick

tarde

TARDE - Time And Rust Duration Ergonomics, a quick way to initalize std::time::Duration values

4 releases

0.2.0 Sep 11, 2019
0.1.2 Sep 10, 2019
0.1.1 Sep 10, 2019
0.1.0 Sep 10, 2019

#24 in #ergonomics

35 downloads per month

Custom license

13KB
271 lines

TARDE

license Crates.io

Linux: Build Status

Windows: Build Status

TARDE (tar-dee, Time And Rust Duration Ergonomics) is a small library to allow for better ergonomics when using std::time::Duration.

Example

use std::time::Instant;
use tarde::{During, Error};

fn main() -> Result<(), tarde::Error> {
    let now = time::Instant::now();
    thread::sleep(10.millis()?); 

    Ok(assert!(now.elapsed() >= 10.millis()?))
}

lib.rs:

TARDE (tar-dee, Time And Rust Duration Ergonomics A simple wrapper to '{integer}' types that improves ergonomics around std::time::Duration

Example:

use std::time::{Instant, Duration};
use std::thread;
use tarde::*;

// Before:
fn std_way() {
    let x: u64 = 10;
    let now = Instant::now();
    thread::sleep(Duration::from_millis(2569));

    assert!(now.elapsed() >= Duration::from_millis(x));
}

// After:
fn main() -> Result<(), Error> {
   let x = 10;
   let now = Instant::now();
   thread::sleep(x.millis()?); 

   Ok(assert!(now.elapsed() >= x.millis()?))
}

Dependencies

~2MB
~47K SLoC