From 4154e1aad87e4ed97f0ee1e89a6e6eb3b127a6d2 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Wed, 15 May 2024 23:05:34 -0400 Subject: [PATCH] Task has crud --- pttodoer/src/main.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/pttodoer/src/main.rs b/pttodoer/src/main.rs index 8ffe24c..fb9af62 100644 --- a/pttodoer/src/main.rs +++ b/pttodoer/src/main.rs @@ -24,6 +24,40 @@ impl Task { assert!(false); false } + + fn get(&self, k: String) -> Option { + match self.0.get(k) { + Some(v) => Some( + serde_yaml::to_string(v) + .unwrap() + .trim() + .to_string() + ), + None => None, + } + } + + fn set(&mut self, k: String, v: String) { + self.0.insert( + serde_yaml::Value::String(k), + serde_yaml::Value::String(v) + ); + } +} + +#[cfg(test)] +mod test_task { + use super::*; + + #[test] + fn crud() { + let mut t = Task::new(); + t.set("k".to_string(), "v".to_string()); + assert_eq!( + t.get("k".to_string()), + Some("v".to_string()), + ); + } } #[derive(Debug)]