kbvm/xkb/level.rs
1#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
2pub(crate) struct Level(u32);
3
4impl Level {
5 pub(crate) const ONE: Self = Self::new(1).unwrap();
6
7 pub(crate) const fn new(level: u32) -> Option<Level> {
8 if level < 1 {
9 return None;
10 }
11 Some(Self(level))
12 }
13
14 pub(crate) const fn raw(self) -> u32 {
15 self.0
16 }
17
18 pub(crate) const fn to_offset(self) -> usize {
19 self.0 as usize - 1
20 }
21}