1use std::fmt;
2
3#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
4pub struct WindowId(pub u64);
5
6impl WindowId {
7 pub const PRIMARY: Self = Self(0);
8
9 pub const fn new(id: u64) -> Self {
10 Self(id)
11 }
12
13 pub const fn get(self) -> u64 {
14 self.0
15 }
16
17 pub const fn is_primary(self) -> bool {
18 self.0 == 0
19 }
20}
21
22impl fmt::Display for WindowId {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 write!(f, "window#{}", self.0)
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31
32 #[test]
33 fn primary_is_zero() {
34 assert_eq!(WindowId::PRIMARY.get(), 0);
35 assert!(WindowId::PRIMARY.is_primary());
36 assert!(!WindowId::new(3).is_primary());
37 assert_eq!(format!("{}", WindowId::new(7)), "window#7");
38 }
39}