matrix_sdk_ui/room_list_service/sorters/mod.rs
1// Copyright 2024 The Matrix.org Foundation C.I.C.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! A collection of room sorters.
16
17mod lexicographic;
18mod name;
19mod recency;
20
21use std::cmp::Ordering;
22
23pub use lexicographic::new_sorter as new_sorter_lexicographic;
24pub use name::new_sorter as new_sorter_name;
25pub use recency::new_sorter as new_sorter_recency;
26
27use super::Room;
28
29/// A trait “alias” that represents a _sorter_.
30///
31/// A sorter is simply a function that receives two `&Room`s and returns a
32/// [`Ordering`].
33pub trait Sorter: Fn(&Room, &Room) -> Ordering {}
34
35impl<F> Sorter for F where F: Fn(&Room, &Room) -> Ordering {}
36
37/// Type alias for a boxed sorter function.
38pub type BoxedSorterFn = Box<dyn Sorter + Send + Sync>;