diff --git a/src/db.rs b/src/db.rs index 3601c4d..6e64472 100644 --- a/src/db.rs +++ b/src/db.rs @@ -3,6 +3,7 @@ use std::hash::{Hash}; use std::fs; use std::io::{self, Write, BufRead}; +use std::fmt; // TODO: use this structure in HashSet of items @@ -12,12 +13,35 @@ pub struct Item { pub content: String } + impl Item { pub fn from(s: String) -> Item { Item { id: s, content: String::from("") } } } +impl fmt::Display for Item { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + writeln!(f, "{}", self.id)?; + writeln!(f, "---------")?; + writeln!(f, "{}", self.content) + } +} + +pub fn test_items() { + let item1 = Item::from("item1".to_string()); + let item2 = Item::from("item2".to_string()); + + let mut hs = HashSet::::new(); + hs.insert(item1); + hs.insert(item2); + + for item in hs.iter() { + println!("item: {}", item) + } + +} + pub struct DB { pub items: HashSet:: diff --git a/src/main.rs b/src/main.rs index 14f8144..a8c0e7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,6 +87,8 @@ fn list() -> io:: Result<()> { } fn main() -> io::Result<()> { + db::test_items(); + return Ok(()); let cli = Cli::parse(); match &cli.command { Some(Commands::Init) => {