mls_rs_core/
protocol_version.rs1use core::ops::Deref;
6
7use mls_rs_codec::{MlsDecode, MlsEncode, MlsSize};
8
9#[derive(
11 Debug, Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd, MlsSize, MlsEncode, MlsDecode,
12)]
13#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15#[repr(transparent)]
16pub struct ProtocolVersion(u16);
17
18impl From<u16> for ProtocolVersion {
19 fn from(value: u16) -> Self {
20 ProtocolVersion(value)
21 }
22}
23
24impl From<ProtocolVersion> for u16 {
25 fn from(value: ProtocolVersion) -> Self {
26 value.0
27 }
28}
29
30impl Deref for ProtocolVersion {
31 type Target = u16;
32
33 fn deref(&self) -> &Self::Target {
34 &self.0
35 }
36}
37
38impl ProtocolVersion {
39 pub const MLS_10: ProtocolVersion = ProtocolVersion(1);
41
42 pub const fn new(value: u16) -> ProtocolVersion {
44 ProtocolVersion(value)
45 }
46
47 pub const fn raw_value(&self) -> u16 {
49 self.0
50 }
51
52 pub fn all() -> impl Iterator<Item = ProtocolVersion> {
54 [Self::MLS_10].into_iter()
55 }
56}