From e62722e3979c51f74c7767e68612ef2e7330c604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Fri, 8 Jul 2022 14:08:38 +0200 Subject: [PATCH] Add JSON support. --- Cargo.lock | 45 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/habit.rs | 8 +++++--- src/main.rs | 1 - 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b128dd3..697cba7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,10 +82,18 @@ dependencies = [ name = "htracker" version = "0.1.0" dependencies = [ + "serde", + "serde_json", "structopt", "uuid", ] +[[package]] +name = "itoa" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" + [[package]] name = "lazy_static" version = "1.4.0" @@ -176,6 +184,43 @@ dependencies = [ "getrandom", ] +[[package]] +name = "ryu" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" + +[[package]] +name = "serde" +version = "1.0.138" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.138" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +dependencies = [ + "itoa", + "ryu", + "serde", +] + [[package]] name = "strsim" version = "0.8.0" diff --git a/Cargo.toml b/Cargo.toml index 3d7d1cd..c38691c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,5 @@ license = "AGPL-3.0-or-later" [dependencies] structopt = "0.3" uuid = { version = "1.1", features = [ "v4", "fast-rng", "macro-diagnostics" ] } +serde = { version = "1.0", features = [ "derive" ] } +serde_json = "1.0" diff --git a/src/habit.rs b/src/habit.rs index 004a49c..c3270c8 100644 --- a/src/habit.rs +++ b/src/habit.rs @@ -17,10 +17,12 @@ */ use uuid::Uuid; +use serde::{Serialize, Deserialize}; +#[derive(Serialize, Deserialize)] pub struct Habit { - uid:Uuid, + uid:String, name:String, bad:bool, weight:u8, @@ -32,14 +34,14 @@ impl Habit { Self { - uid: Uuid::new_v4(), + uid: Uuid::new_v4().hyphenated().to_string(), name, bad, weight, } } - pub fn get_uid(&self) -> String { self.uid.to_string() } + pub fn get_uid(&self) -> &String { &self.uid } pub fn get_name(&self) -> &String { &self.name } pub fn get_bad(&self) -> bool { self.bad } pub fn get_weight(&self) -> u8 { self.weight } diff --git a/src/main.rs b/src/main.rs index e70dfca..0a8cdde 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,6 @@ use structopt::clap::AppSettings; use std::env; use std::path::PathBuf; use std::fs; -//use std::result::Result; mod habit; mod habitmgr;