roopes_core/patterns/command/
hashable.rs1use crate::prelude::*;
8use std::hash::Hash;
9
10#[derive(Debug)]
14pub struct Hashable<D, H>
15where
16 D: Command,
17 H: Hash + Eq,
18{
19 command: D,
20 id: H,
21}
22
23impl<D, H> Hashable<D, H>
24where
25 D: Command,
26 H: Hash + Eq,
27{
28 pub fn new(
31 command: D,
32 id: H,
33 ) -> Hashable<D, H>
34 {
35 Hashable { command, id }
36 }
37}
38
39impl<D, H> Eq for Hashable<D, H>
40where
41 D: Command,
42 H: Hash + Eq,
43{
44}
45
46impl<D, H> PartialEq<Self> for Hashable<D, H>
47where
48 D: Command,
49 H: Hash + Eq,
50{
51 fn eq(
52 &self,
53 other: &Self,
54 ) -> bool
55 {
56 self.id.eq(&other.id)
57 }
58}
59
60impl<D, H> Hash for Hashable<D, H>
61where
62 D: Command,
63 H: Hash + Eq,
64{
65 fn hash<R: std::hash::Hasher>(
66 &self,
67 state: &mut R,
68 )
69 {
70 self.id.hash(state);
71 }
72}
73
74impl<D, H> Command for Hashable<D, H>
75where
76 D: Command,
77 H: Hash + Eq,
78{
79 fn execute(&self)
80 {
81 self.command.execute();
82 }
83}