diff --git a/Cargo.toml b/Cargo.toml index f0f2e26..feaab45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "julid-rs" -version = "1.6.1803" +version = "1.6.18033" authors = ["Joe Ardent "] edition = "2021" keywords = ["ulid", "library", "sqlite", "extension", "julid"] @@ -11,8 +11,7 @@ license-file = "LICENSE.md" repository = "https://gitlab.com/nebkor/julid" [features] -default = ["chrono", "serde", "sqlx"] # just the regular crate -chrono = ["dep:chrono"] +default = ["serde", "sqlx"] # just the regular crate serde = ["dep:serde"] sqlx = ["dep:sqlx"] @@ -29,9 +28,9 @@ rand = "0.8" # for the CLI clap = { version = "4.3", default-features = false, features = ["help", "usage", "std", "derive"] } +chrono = { version = "0.4", default-features = false, features = ["std", "time"] } # all other deps are optional -chrono = { version = "0.4", optional = true, default-features = false, features = ["std", "time"] } serde = { version = "1.0", features = ["derive"], optional = true } sqlx = { version = "0.7", features = ["sqlite"], default-features = false, optional = true } sqlite-loadable = { version = "0.0.5", optional = true } diff --git a/README.md b/README.md index efa7e3e..258bb53 100644 --- a/README.md +++ b/README.md @@ -188,9 +188,7 @@ That's about 24,000 IDs/millisecond; 24 *MILLION* per second! The default optional Cargo features include implementations of traits for getting Julids into and out of SQLite with [SQLx](https://github.com/launchbadge/sqlx), and for generally serializing/deserializing with [Serde](https://serde.rs/), via the `sqlx` and `serde` features, -respectively. One final default optional feature, `chrono`, uses the Chrono crate to return the -timestamp as a [`DateTime`](https://docs.rs/chrono/latest/chrono/struct.DateTime.html) by adding a -`created_at(&self)` method to `Julid`. +respectively. Something to note: don't enable the `plugin` feature in your Cargo.toml if you're using this crate inside your Rust application, especially if you're *also* loading it as an extension in SQLite in diff --git a/VERSION b/VERSION index 9a0be07..f8903b6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.61803 +1.618033 diff --git a/src/bin/gen.rs b/src/bin/gen.rs index 616ba8f..51a9139 100644 --- a/src/bin/gen.rs +++ b/src/bin/gen.rs @@ -2,17 +2,28 @@ use clap::Parser; use julid::Julid; #[derive(Debug, Parser)] -#[command(author, version = "1.61803", about = "Generate and print Julids")] +#[command(author, version = "1.618033", about = "Generate and print Julids")] struct Cli { + #[clap(help = "Print the timestamp of the given Julid", short, long)] + pub timestamp: Option, #[clap(help = "Number of Julids to generate", default_value_t = 1)] pub num: usize, } fn main() { let cli = Cli::parse(); - let num = cli.num; - - for _ in 0..num { - println!("{}", Julid::new()); + if let Some(ts) = cli.timestamp { + if let Ok(ts) = Julid::from_string(&ts) { + println!("{}", ts.created_at()); + } else { + eprintln!("Could not parse input '{}' as a Julid", ts); + std::process::exit(1); + } + } else { + // Just print some Julids + let num = cli.num; + for _ in 0..num { + println!("{}", Julid::new()); + } } } diff --git a/src/julid.rs b/src/julid.rs index e009ad7..0d4a993 100644 --- a/src/julid.rs +++ b/src/julid.rs @@ -117,7 +117,6 @@ impl Julid { (self.0 & bitmask!(UNIQUE_BITS)) as u64 } - #[cfg(feature = "chrono")] /// Returns the timestamp as a `chrono::DateTime` (feature /// `chrono` (default)) pub fn created_at(&self) -> chrono::DateTime {