sarmio 0.1.1

Distributed unique ID generator.
Documentation
  • Coverage
  • 14.29%
    1 out of 7 items documented1 out of 1 items with examples
  • Size
  • Source code size: 4.81 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • ycd/sarmio
    3 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ycd

Distributed unique ID generator inspired by Twitter's snowflake. https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake.html

How to use?

First of all, add this as a dependency to your cargo.toml

[dependencies]
sarmio = "0.1"

Example

fn main() { // Create new Sarmio instance with a machine-id of 255. let mut s = sarmio::Sarmio::new(255);

// Sarmio implements Iterator
// Which means you can iterate over it to create new IDs.
let v = match s.next() {
    Some(s) => s,
    None => 0,
};
println!("{}", v);

// Decompose it, get the values like
// Unix time in that moment, machine id
// and the Unique ID.
let p = sarmio::decompose(v);  

println!("{:?}", p);    // {"id": 18190711796065697536, "time": 1610671519, "machine-id": 255}

}