|
|
@ -3,6 +3,7 @@ use std::hash::{Hash}; |
|
|
|
|
|
|
|
|
|
|
|
use std::fs; |
|
|
|
use std::fs; |
|
|
|
use std::io::{self, Write, BufRead}; |
|
|
|
use std::io::{self, Write, BufRead}; |
|
|
|
|
|
|
|
use std::fmt; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: use this structure in HashSet of items
|
|
|
|
// TODO: use this structure in HashSet of items
|
|
|
@ -12,12 +13,35 @@ pub struct Item { |
|
|
|
pub content: String |
|
|
|
pub content: String |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Item { |
|
|
|
impl Item { |
|
|
|
pub fn from(s: String) -> Item { |
|
|
|
pub fn from(s: String) -> Item { |
|
|
|
Item { id: s, content: String::from("") } |
|
|
|
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 struct DB { |
|
|
|
pub items: HashSet::<String> |
|
|
|
pub items: HashSet::<String> |
|
|
|