From 0cbb6b43ca8fd27db69477c844303c6d1faf3762 Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Thu, 5 Sep 2024 10:10:41 +0000 Subject: [PATCH] display for item --- src/db.rs | 24 ++++++++++++++++++++++++ src/main.rs | 2 ++ 2 files changed, 26 insertions(+) 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) => {