Function combid::gen [] [src]

pub fn gen<R: Rng>(rng: &mut R) -> Result<i64, IdError>

Generates a Combid (Combined Identifier), a combination of a timestamp and some random bits. The timestamp ensures they are ordered chronologically, and the random bits ensure that each ID is unique, even if thousands of people are creating IDs at the same time.

timestamp - 5 bytes (40 bits) - 4 bytes from seconds and the other ones from nanoseconds
random number - 3 bytes (24 bits) - gives us up to 16_777_216 possible values

Examples

extern crate combid;
extern crate rand;

let mut rng = rand::thread_rng();

let id = match combid::gen(&mut rng) {
    Ok(v) => v,
    Err(e) => panic!(e), // handle error
};
println!("combid: {}", id);