Browse Source

display for item

db-refactoring
Coin de Gamma 4 months ago
parent
commit
0cbb6b43ca
  1. 24
      src/db.rs
  2. 2
      src/main.rs

24
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::<Item>::new();
hs.insert(item1);
hs.insert(item2);
for item in hs.iter() {
println!("item: {}", item)
}
}
pub struct DB {
pub items: HashSet::<String>

2
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) => {

Loading…
Cancel
Save