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(all(feature = "ffi", not(test)), safer_ffi_gen::ffi_type)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16#[repr(transparent)]
17pub struct ProtocolVersion(u16);
18
19impl From<u16> for ProtocolVersion {
20 fn from(value: u16) -> Self {
21 ProtocolVersion(value)
22 }
23}
24
25impl From<ProtocolVersion> for u16 {
26 fn from(value: ProtocolVersion) -> Self {
27 value.0
28 }
29}
30
31impl Deref for ProtocolVersion {
32 type Target = u16;
33
34 fn deref(&self) -> &Self::Target {
35 &self.0
36 }
37}
38
39impl ProtocolVersion {
40 pub const MLS_10: ProtocolVersion = ProtocolVersion(1);
42
43 pub const fn new(value: u16) -> ProtocolVersion {
45 ProtocolVersion(value)
46 }
47
48 pub const fn raw_value(&self) -> u16 {
50 self.0
51 }
52
53 pub fn all() -> impl Iterator<Item = ProtocolVersion> {
55 [Self::MLS_10].into_iter()
56 }
57}