1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pub trait IsModuleChannelReference {}

#[derive(Clone, Debug, PartialEq)]
pub struct ModuleChannelReference {
    pub module_id: u16,
    pub channel_id: u16,
}

impl IsModuleChannelReference for ModuleChannelReference {}

impl From<u64> for ModuleChannelReference {
    fn from(v: u64) -> Self {
        let module_id = (v >> 16) as u16;
        let channel_id = (v) as u16;
        ModuleChannelReference {
            module_id,
            channel_id,
        }
    }
}

impl Into<u64> for ModuleChannelReference {
    fn into(self) -> u64 {
        let Self {
            module_id,
            channel_id,
        } = self;
        (u64::from(module_id) << 16) | u64::from(channel_id)
    }
}

impl<'a> Into<u64> for &'a ModuleChannelReference {
    fn into(self) -> u64 {
        (u64::from(self.module_id) << 16) | u64::from(self.channel_id)
    }
}