diff options
author | metamuffin <metamuffin@disroot.org> | 2023-08-07 13:46:22 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-08-07 13:46:22 +0200 |
commit | a2e557e648cf253d47e9f4b9dd99ee657610f294 (patch) | |
tree | 350fe5868c9f7d890c79b2489b307c263ed7c307 /common/src | |
parent | 908db5458b07d7a13f24c755d340ab3c1917e8a8 (diff) | |
download | jellything-a2e557e648cf253d47e9f4b9dd99ee657610f294.tar jellything-a2e557e648cf253d47e9f4b9dd99ee657610f294.tar.bz2 jellything-a2e557e648cf253d47e9f4b9dd99ee657610f294.tar.zst |
extend sort and filter
Diffstat (limited to 'common/src')
-rw-r--r-- | common/src/helpers.rs | 20 | ||||
-rw-r--r-- | common/src/lib.rs | 20 |
2 files changed, 31 insertions, 9 deletions
diff --git a/common/src/helpers.rs b/common/src/helpers.rs new file mode 100644 index 0000000..5150667 --- /dev/null +++ b/common/src/helpers.rs @@ -0,0 +1,20 @@ +use std::ops::Deref; + +#[derive(PartialEq, PartialOrd)] +pub struct SortAnyway<T>(pub T); + +impl<T: PartialEq> Eq for SortAnyway<T> { + fn assert_receiver_is_total_eq(&self) {} +} +impl<T: PartialOrd> Ord for SortAnyway<T> { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.partial_cmp(&other).unwrap() + } +} + +impl<T> Deref for SortAnyway<T> { + type Target = T; + fn deref(&self) -> &Self::Target { + &self.0 + } +} diff --git a/common/src/lib.rs b/common/src/lib.rs index 9d5a31e..b02f58c 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -4,12 +4,14 @@ Copyright (C) 2023 metamuffin <metamuffin.org> */ pub mod config; +pub mod helpers; pub mod r#impl; use bincode::{Decode, Encode}; +#[cfg(feature = "rocket")] use rocket::{FromFormField, UriDisplayQuery}; use serde::{Deserialize, Serialize}; -use std::path::PathBuf; +use std::{collections::BTreeMap, path::PathBuf}; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct Node { @@ -38,7 +40,7 @@ pub struct NodePublic { #[serde(default)] pub description: Option<String>, #[serde(default)] pub index: Option<usize>, #[serde(default)] pub media: Option<MediaInfo>, - #[serde(default)] pub ratings: Vec<Rating>, + #[serde(default)] pub ratings: BTreeMap<Rating, f64>, #[serde(default)] pub federated: Option<String>, } @@ -107,15 +109,15 @@ pub struct SourceTrack { pub default_duration: Option<u64>, } -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] #[serde(rename_all = "snake_case")] pub enum Rating { - RottenTomatoes(u8), - Metacritic(u8), - Imdb(f32), - YoutubeViews(usize), - YoutubeLikes(usize), - YoutubeFollowers(usize), + RottenTomatoes, + Metacritic, + Imdb, + YoutubeViews, + YoutubeLikes, + YoutubeFollowers, } #[derive(Debug, Clone, Deserialize, Serialize)] |