diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-30 12:59:46 +0100 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-30 12:59:46 +0100 |
commit | 620d82cc3910d21940e9cc737900440be3b0ced4 (patch) | |
tree | 82f8b4b9e93deed5f72a61c5784d6fff5c5bc971 /lib/src/lib.rs | |
parent | Frontend: Add props to the OSSE Component (diff) | |
download | OSSE-620d82cc3910d21940e9cc737900440be3b0ced4.tar.gz OSSE-620d82cc3910d21940e9cc737900440be3b0ced4.tar.bz2 OSSE-620d82cc3910d21940e9cc737900440be3b0ced4.zip |
Misc: Add local lib crate to share common structs
Diffstat (limited to '')
-rw-r--r-- | lib/src/lib.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/src/lib.rs b/lib/src/lib.rs new file mode 100644 index 0000000..a11637f --- /dev/null +++ b/lib/src/lib.rs @@ -0,0 +1,50 @@ +pub mod lib { + use serde::{Serialize,Deserialize}; + use std::sync::Arc; + use std::hash::{Hash, Hasher}; + use std::cmp::Ordering; + + #[derive(Serialize, Deserialize, Debug)] + pub struct CrawledResource { + pub url: String, + pub content: String, + } + + #[derive(Debug, Clone, Serialize, Deserialize)] + pub struct IndexedResource { + pub url: String, + pub title: String, + pub description: String, + pub priority: u32, + pub word: Arc<String>, + } + + //We implement PartialEq, Eq and Hash to ignore the priority field. + impl PartialEq for IndexedResource { + fn eq(&self, other: &Self) -> bool { + self.url == other.url && self.word == other.word + } + } + impl Eq for IndexedResource {} + + impl PartialOrd for IndexedResource { + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { + Some(self.cmp(other)) + } + } + + impl Ord for IndexedResource { + fn cmp(&self, other: &Self) -> Ordering { + self.priority.cmp(&other.priority).reverse() + } + } + + impl Hash for IndexedResource { + fn hash<H: Hasher>(&self, state: &mut H) { + self.url.hash(state); + self.word.hash(state); + } + } + + +} \ No newline at end of file |