update version, add way to get timestamp from input to julid-gen, chrono now mandatory

This commit is contained in:
Joe Ardent 2023-09-03 13:16:04 -07:00
parent f4ac603ac8
commit d9e68f057c
5 changed files with 21 additions and 14 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "julid-rs"
version = "1.6.1803"
version = "1.6.18033"
authors = ["Joe Ardent <code@ardent.nebcorp.com>"]
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 }

View File

@ -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

View File

@ -1 +1 @@
1.61803
1.618033

View File

@ -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<String>,
#[clap(help = "Number of Julids to generate", default_value_t = 1)]
pub num: usize,
}
fn main() {
let cli = Cli::parse();
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());
}
}
}

View File

@ -117,7 +117,6 @@ impl Julid {
(self.0 & bitmask!(UNIQUE_BITS)) as u64
}
#[cfg(feature = "chrono")]
/// Returns the timestamp as a `chrono::DateTime<chrono::Utc>` (feature
/// `chrono` (default))
pub fn created_at(&self) -> chrono::DateTime<chrono::Utc> {