buswatch_types/
version.rs1use crate::SCHEMA_VERSION;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10#[cfg_attr(feature = "minicbor", derive(minicbor::Encode, minicbor::Decode))]
11pub struct SchemaVersion {
12 #[cfg_attr(feature = "minicbor", n(0))]
14 pub major: u32,
15
16 #[cfg_attr(feature = "minicbor", n(1))]
18 pub minor: u32,
19}
20
21impl SchemaVersion {
22 pub const fn new(major: u32, minor: u32) -> Self {
24 Self { major, minor }
25 }
26
27 pub const fn current() -> Self {
29 Self {
30 major: SCHEMA_VERSION,
31 minor: 0,
32 }
33 }
34
35 pub fn is_compatible(&self) -> bool {
39 self.major == SCHEMA_VERSION
40 }
41}
42
43impl Default for SchemaVersion {
44 fn default() -> Self {
45 Self::current()
46 }
47}