diff --git a/src/db.rs b/src/db.rs index baa72a4..6f5f14a 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,13 +1,12 @@ use std::collections::HashSet; -use std::hash::{Hash}; +use std::hash::{Hash, Hasher}; use std::fs; use std::io::{self, Write, BufRead}; use std::fmt; +use std::cmp::PartialEq; -// TODO: use this structure in HashSet of items -#[derive(PartialEq, Eq, Hash)] pub struct Item { pub id: String, pub content: String @@ -20,6 +19,20 @@ impl Item { } } +impl PartialEq for Item { + fn eq(&self, other: &Self) -> bool { + self.id == other.id + } +} + +impl Eq for Item {} + +impl Hash for Item { + fn hash(&self, state: &mut H) { + self.id.hash(state); + } +} + impl fmt::Display for Item { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln!(f, "{}", self.id)?;