feat: list sorting #42
@ -5,6 +5,7 @@ mod route;
|
||||
mod schema;
|
||||
mod server;
|
||||
mod query;
|
||||
mod utils;
|
||||
|
||||
use components::app::App;
|
||||
use dioxus::prelude::*;
|
||||
|
1
src/utils/mod.rs
Normal file
1
src/utils/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub(crate) mod reverse_ord_option;
|
||||
|
31
src/utils/reverse_ord_option.rs
Normal file
31
src/utils/reverse_ord_option.rs
Normal 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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user
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?