1use std::{hash::Hash, sync::Arc};
2
3use crate::{router::Router, types::Callback};
4
5#[derive(Clone)]
6pub struct Entry {
7 pub id: &'static str,
8 pub priority: i8,
9 pub router: Arc<Box<dyn Router>>,
10 pub callback: Arc<Callback>,
11}
12
13impl Entry {
14 pub fn get_priority(&self) -> i8 {
15 self.priority
16 }
17
18 pub fn get_router(&self) -> &dyn Router {
19 self.router.as_ref().as_ref()
20 }
21
22 pub fn get_handler(&self) -> Arc<Callback> {
23 self.callback.clone()
24 }
25}
26
27impl PartialEq for Entry {
28 fn eq(&self, other: &Self) -> bool {
29 self.id == other.id
30 }
31}
32
33impl Eq for Entry {}
34
35impl Ord for Entry {
36 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
37 self.priority.cmp(&other.priority)
38 }
39}
40
41impl PartialOrd for Entry {
42 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
43 Some(self.cmp(other))
44 }
45}
46
47impl Hash for Entry {
48 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
49 self.id.hash(state)
50 }
51}