rusty_ulid 0.3.0

Rust ULID (Universally Unique Lexicographically Sortable Identifier) generation and processing
docs.rs failed to build rusty_ulid-0.3.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: rusty_ulid-2.0.0

rusty_ulid

Build Status codecov Crates.io docs.rs dependency status

This is a Rust implementation of the ULID Universally Unique Lexicographically Sortable Identifiers.

This crate requires Rust 1.26 or later because it is using u128.

Take a look at the changelog for a detailed list of all changes.

Features

  • lenient parsing of ULID strings as specified in Crockford Base32 Encoding.
  • straight-forward creation of string and binary ULIDs.
  • backed by u128 for efficiency.

Quickstart

extern crate rusty_ulid;
use rusty_ulid::new_ulid_string;
use rusty_ulid::new_ulid_bytes;

// Generate a ULID string
let ulid_string: String = new_ulid_string();
assert_eq!(ulid_string.len(), 26);

// Generate ULID bytes
let ulid_bytes: [u8; 16] = new_ulid_bytes();
assert_eq!(ulid_bytes.len(), 16);
extern crate rusty_ulid;
use rusty_ulid::Ulid;

// Generate a ULID
let ulid = Ulid::new();

// Generate a string for a ULID
let ulid_string = ulid.to_string();

// Create ULID from a string
let result = Ulid::from_str(&ulid_string);

assert_eq!(Ok(ulid), result);
extern crate rusty_ulid;
use rusty_ulid::Ulid;

// Alternative way to parse a ULID string
// This example assumes a function returning a Result.
let ulid: Ulid = "01CAT3X5Y5G9A62FH1FA6T9GVR".parse()?;

let datetime = ulid.datetime();
assert_eq!(datetime.to_string(), "2018-04-11 10:27:03.749 UTC");

Benchmark

Run the benchmarks by executing cargo bench.

Executable

Install the executable by executing cargo install or cargo install --force if a prior version was already installed.

rusty_ulid usage examples

Just calling the executable generates a ULID.

$ rusty_ulid
01CB2EM1J4EMBWRBJK877TM17S

Calling the executable with -v or --verbose generates a ULID and prints its timestamp.

$ rusty_ulid -v
01CB2EMMMV8P51SCR9ZH8K64CX
2018-04-14 16:08:33.691 UTC

Calling the executable with any number of ULIDs checks them for validity and returns 0 if they are all fine...

$ rusty_ulid 01CB2EM1J4EMBWRBJK877TM17S 01CB2EMMMV8P51SCR9ZH8K64CX
$ echo $?
0

... or 1 if any given value is invalid, printing the invalid values to err.

$ rusty_ulid 01CB2EM1J4EMBWRBJK877TM17S foo 01CB2EMMMV8P51SCR9ZH8K64CX
Invalid ULID strings: ["foo"]
$ echo $?
1

In addition to that, -v or --verbose will print the ULIDs with their respective timestamp.

$ rusty_ulid -v 01CB2EM1J4EMBWRBJK877TM17S foo 01CB2EMMMV8P51SCR9ZH8K64CX
01CB2EM1J4EMBWRBJK877TM17S
2018-04-14 16:08:14.148 UTC

01CB2EMMMV8P51SCR9ZH8K64CX
2018-04-14 16:08:33.691 UTC

Invalid ULID strings: ["foo"]
$ echo $?
1

Executing rusty_ulid -h will print the help.

License

Licensed under either of

at your option.

Licensing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.