timed-option

Crates.iotimed-option
lib.rstimed-option
version0.2.2
sourcesrc
created_at2024-06-09 15:10:55.993295
updated_at2024-06-10 16:18:11.838604
descriptionA simple library for options with TTLs.
homepage
repositoryhttps://github.com/redmannequin/timed-option
max_upload_size
id1266430
size14,637
Flavio B. (redmannequin)

documentation

README

timed-option

A simple library for options with TTLs

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

use timed_option::{TimedOption, TimedValue};

let ttl = Duration::from_millis(10);
let access_token = TimedOption::<_, Instant>::new("token", ttl);
assert_eq!(true, access_token.is_some());
thread::sleep(ttl);
assert_eq!(false, access_token.is_some());

match access_token.into_option() {
    Some(_) => println!("is_some"),
    None => println!("is_none")
}

match access_token.into_timed_value() {
    TimedValue::Valid(_) => println!("is_valid"),
    TimedValue::Expired(_) => println!("is_expired"),
    TimedValue::None => println!("is_none")
}
Commit count: 6

cargo fmt