diff --git a/Cargo.lock b/Cargo.lock index 4ceeb6c..752a68d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,6 +32,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "chrono" version = "0.4.11" @@ -58,6 +64,17 @@ dependencies = [ "vec_map", ] +[[package]] +name = "getrandom" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "hermit-abi" version = "0.1.8" @@ -92,6 +109,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "ppv-lite86" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" + [[package]] name = "proc-macro2" version = "1.0.9" @@ -110,6 +133,47 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core", +] + [[package]] name = "redox_syscall" version = "0.1.56" @@ -188,6 +252,7 @@ dependencies = [ "serde", "serde_derive", "toml", + "uuid", ] [[package]] @@ -202,12 +267,27 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +[[package]] +name = "uuid" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" +dependencies = [ + "rand", +] + [[package]] name = "vec_map" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "winapi" version = "0.3.8" diff --git a/Cargo.toml b/Cargo.toml index 10479dd..3cd3d9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,4 @@ clap = "2.33.0" serde = "*" serde_derive = "*" toml = "0.5" +uuid = { version = "0.8", features = ["v4"] } diff --git a/README.md b/README.md index a31f476..f930916 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,12 @@ tell you that you have 15 days up to it. ## TODO -- [ ] Add unique identifier for each event +- [x] Add unique identifier for each event - [ ] Removing events - [ ] Replace `dbg!` with [env_logger](https://crates.io/crates/env_logger) (reasoning: Although `dbg!` is nice and dandy, it can't be disabled, and that's bad UI) +- [ ] Remove `unwrap()`s (for example, in the argument parsing). ## License diff --git a/src/eventlist/event.rs b/src/eventlist/event.rs index 3a0d510..1d1f736 100644 --- a/src/eventlist/event.rs +++ b/src/eventlist/event.rs @@ -19,6 +19,7 @@ use chrono::prelude::*; use serde_derive::Deserialize; use serde_derive::Serialize; +use uuid::Uuid; #[derive(Serialize, Deserialize, Debug)] pub struct Date { @@ -42,6 +43,7 @@ pub enum EventDateType { #[derive(Serialize, Deserialize, Debug)] pub struct Event { + id: String, description: String, due: EventDateType, } @@ -50,7 +52,9 @@ impl Event { pub fn new_on_date(description: &str, date: &str) -> Self { let fake_datetime = format!("{} 00:00:00", date); if let Ok(dt) = Utc.datetime_from_str(&fake_datetime, "%Y-%m-%d %H:%M:%S") { + let (id, _, _, _) = Uuid::new_v4().as_fields(); Self { + id: format!("{:x}", id), description: description.into(), due: EventDateType::AllDay(Date { year: dt.year(),