wslplugins_rs/
wsl_version.rs1use std::{
2 fmt::{self, Debug, Display},
3 hash::Hash,
4 ptr,
5};
6
7#[repr(transparent)]
20#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
21pub struct WSLVersion(wslpluginapi_sys::WSLVersion);
22
23impl WSLVersion {
24 #[must_use]
32 #[inline]
33 pub const fn new(major: u32, minor: u32, revision: u32) -> Self {
34 Self(wslpluginapi_sys::WSLVersion {
35 Major: major,
36 Minor: minor,
37 Revision: revision,
38 })
39 }
40
41 #[must_use]
43 #[inline]
44 pub const fn major(&self) -> u32 {
45 self.0.Major
46 }
47
48 #[inline]
50 pub const fn set_major(&mut self, major: u32) {
51 self.0.Major = major;
52 }
53
54 #[must_use]
56 #[inline]
57 pub const fn minor(&self) -> u32 {
58 self.0.Minor
59 }
60
61 #[inline]
63 pub const fn set_minor(&mut self, minor: u32) {
64 self.0.Minor = minor;
65 }
66
67 #[must_use]
69 #[inline]
70 pub const fn revision(&self) -> u32 {
71 self.0.Revision
72 }
73
74 #[inline]
76 pub const fn set_revision(&mut self, revision: u32) {
77 self.0.Revision = revision;
78 }
79}
80
81impl From<wslpluginapi_sys::WSLVersion> for WSLVersion {
82 #[inline]
83 fn from(value: wslpluginapi_sys::WSLVersion) -> Self {
84 Self(value)
85 }
86}
87
88impl From<WSLVersion> for wslpluginapi_sys::WSLVersion {
89 #[inline]
90 fn from(value: WSLVersion) -> Self {
91 value.0
92 }
93}
94
95impl AsRef<WSLVersion> for wslpluginapi_sys::WSLVersion {
96 #[inline]
97 fn as_ref(&self) -> &WSLVersion {
98 unsafe { &*ptr::from_ref(self).cast::<WSLVersion>() }
100 }
101}
102
103impl AsRef<wslpluginapi_sys::WSLVersion> for WSLVersion {
104 #[inline]
105 fn as_ref(&self) -> &wslpluginapi_sys::WSLVersion {
106 &self.0
107 }
108}
109
110impl Default for WSLVersion {
111 #[inline]
112 fn default() -> Self {
113 Self::new(1, 0, 0)
114 }
115}
116
117impl Display for WSLVersion {
118 #[inline]
119 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
120 write!(f, "{}.{}.{}", self.major(), self.minor(), self.revision())
121 }
122}
123
124impl Debug for WSLVersion {
125 #[inline]
126 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
127 f.debug_struct(stringify!(WSLVersion))
128 .field("major", &self.major())
129 .field("minor", &self.minor())
130 .field("revision", &self.revision())
131 .finish()
132 }
133}