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] [package]
name = "julid-rs" name = "julid-rs"
version = "1.6.1803" version = "1.6.18033"
authors = ["Joe Ardent <code@ardent.nebcorp.com>"] authors = ["Joe Ardent <code@ardent.nebcorp.com>"]
edition = "2021" edition = "2021"
keywords = ["ulid", "library", "sqlite", "extension", "julid"] keywords = ["ulid", "library", "sqlite", "extension", "julid"]
@ -11,8 +11,7 @@ license-file = "LICENSE.md"
repository = "https://gitlab.com/nebkor/julid" repository = "https://gitlab.com/nebkor/julid"
[features] [features]
default = ["chrono", "serde", "sqlx"] # just the regular crate default = ["serde", "sqlx"] # just the regular crate
chrono = ["dep:chrono"]
serde = ["dep:serde"] serde = ["dep:serde"]
sqlx = ["dep:sqlx"] sqlx = ["dep:sqlx"]
@ -29,9 +28,9 @@ rand = "0.8"
# for the CLI # for the CLI
clap = { version = "4.3", default-features = false, features = ["help", "usage", "std", "derive"] } 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 # 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 } serde = { version = "1.0", features = ["derive"], optional = true }
sqlx = { version = "0.7", features = ["sqlite"], default-features = false, optional = true } sqlx = { version = "0.7", features = ["sqlite"], default-features = false, optional = true }
sqlite-loadable = { version = "0.0.5", 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 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 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, 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 respectively.
timestamp as a [`DateTime`](https://docs.rs/chrono/latest/chrono/struct.DateTime.html) by adding a
`created_at(&self)` method to `Julid`.
Something to note: don't enable the `plugin` feature in your Cargo.toml if you're using this crate 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 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; use julid::Julid;
#[derive(Debug, Parser)] #[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 { 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)] #[clap(help = "Number of Julids to generate", default_value_t = 1)]
pub num: usize, pub num: usize,
} }
fn main() { fn main() {
let cli = Cli::parse(); 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; let num = cli.num;
for _ in 0..num { for _ in 0..num {
println!("{}", Julid::new()); println!("{}", Julid::new());
} }
} }
}

View File

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