feat: list sorting #42

Merged
matous-volf merged 9 commits from feat/list-sorting into main 2024-09-09 17:09:22 +00:00
3 changed files with 33 additions and 0 deletions
Showing only changes of commit f251c7cce5 - Show all commits

View File

@ -5,6 +5,7 @@ mod route;
mod schema; mod schema;
mod server; mod server;
mod query; mod query;
mod utils;
use components::app::App; use components::app::App;
use dioxus::prelude::*; use dioxus::prelude::*;

1
src/utils/mod.rs Normal file
View File

@ -0,0 +1 @@
pub(crate) mod reverse_ord_option;
coderabbitai[bot] commented 2024-09-09 17:00:59 +00:00 (Migrated from github.com)
Review

Approve module declaration but recommend adding documentation.

The module declaration pub(crate) mod reverse_ord_option; is correctly scoped for internal crate usage. However, it would be beneficial to add documentation to explain the purpose and functionality of this module, especially since it is a new addition to the codebase.

Would you like me to help draft initial documentation for this module?

**Approve module declaration but recommend adding documentation.** The module declaration `pub(crate) mod reverse_ord_option;` is correctly scoped for internal crate usage. However, it would be beneficial to add documentation to explain the purpose and functionality of this module, especially since it is a new addition to the codebase. Would you like me to help draft initial documentation for this module? <!-- This is an auto-generated comment by CodeRabbit -->

View File

@ -0,0 +1,31 @@
use std::cmp::Ordering;
/* The default ordering of `Option`s is `None` being less than `Some`. The purpose of this struct is
to reverse that. */
#[derive(PartialEq)]
pub(crate) struct ReverseOrdOption<'a, T>(&'a Option<T>);
impl<'a, T: Ord> Eq for ReverseOrdOption<'a, T> {}
impl<'a, T: Ord> PartialOrd<Self> for ReverseOrdOption<'a, T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl<'a, T: Ord> Ord for ReverseOrdOption<'a, T> {
fn cmp(&self, other: &Self) -> Ordering {
match (self.0.as_ref(), other.0.as_ref()) {
(None, None) => Ordering::Equal,
(None, Some(_)) => Ordering::Greater,
(Some(_), None) => Ordering::Less,
(Some(self_time), Some(other_time)) => self_time.cmp(other_time)
}
}
}
impl<'a, T> From<&'a Option<T>> for ReverseOrdOption<'a, T> {
fn from(value: &'a Option<T>) -> Self {
ReverseOrdOption(value)
}
}