From a2e557e648cf253d47e9f4b9dd99ee657610f294 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 7 Aug 2023 13:46:22 +0200 Subject: extend sort and filter --- common/src/helpers.rs | 20 ++++++++++++++++++++ common/src/lib.rs | 20 +++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 common/src/helpers.rs (limited to 'common/src') 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(pub T); + +impl Eq for SortAnyway { + fn assert_receiver_is_total_eq(&self) {} +} +impl Ord for SortAnyway { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.partial_cmp(&other).unwrap() + } +} + +impl Deref for SortAnyway { + 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 */ 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, #[serde(default)] pub index: Option, #[serde(default)] pub media: Option, - #[serde(default)] pub ratings: Vec, + #[serde(default)] pub ratings: BTreeMap, #[serde(default)] pub federated: Option, } @@ -107,15 +109,15 @@ pub struct SourceTrack { pub default_duration: Option, } -#[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)] -- cgit v1.2.3-70-g09d2