Browse Source

hashset vs item

db-refactoring
Coin de Gamma 4 months ago
parent
commit
13e67ea136
  1. 19
      src/db.rs

19
src/db.rs

@ -1,13 +1,12 @@
use std::collections::HashSet; use std::collections::HashSet;
use std::hash::{Hash}; use std::hash::{Hash, Hasher};
use std::fs; use std::fs;
use std::io::{self, Write, BufRead}; use std::io::{self, Write, BufRead};
use std::fmt; use std::fmt;
use std::cmp::PartialEq;
// TODO: use this structure in HashSet of items
#[derive(PartialEq, Eq, Hash)]
pub struct Item { pub struct Item {
pub id: String, pub id: String,
pub content: 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<H: Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
}
impl fmt::Display for Item { impl fmt::Display for Item {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "{}", self.id)?; writeln!(f, "{}", self.id)?;

Loading…
Cancel
Save