use std::{
fmt::{self, Debug, Display},
hash::Hash,
ptr,
};
#[repr(transparent)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WSLVersion(wslpluginapi_sys::WSLVersion);
impl WSLVersion {
#[must_use]
#[inline]
pub const fn new(major: u32, minor: u32, revision: u32) -> Self {
Self(wslpluginapi_sys::WSLVersion {
Major: major,
Minor: minor,
Revision: revision,
})
}
#[must_use]
#[inline]
pub const fn major(&self) -> u32 {
self.0.Major
}
#[inline]
pub const fn set_major(&mut self, major: u32) {
self.0.Major = major;
}
#[must_use]
#[inline]
pub const fn minor(&self) -> u32 {
self.0.Minor
}
#[inline]
pub const fn set_minor(&mut self, minor: u32) {
self.0.Minor = minor;
}
#[must_use]
#[inline]
pub const fn revision(&self) -> u32 {
self.0.Revision
}
#[inline]
pub const fn set_revision(&mut self, revision: u32) {
self.0.Revision = revision;
}
}
impl From<wslpluginapi_sys::WSLVersion> for WSLVersion {
#[inline]
fn from(value: wslpluginapi_sys::WSLVersion) -> Self {
Self(value)
}
}
impl From<WSLVersion> for wslpluginapi_sys::WSLVersion {
#[inline]
fn from(value: WSLVersion) -> Self {
value.0
}
}
impl AsRef<WSLVersion> for wslpluginapi_sys::WSLVersion {
#[inline]
fn as_ref(&self) -> &WSLVersion {
unsafe { &*ptr::from_ref(self).cast::<WSLVersion>() }
}
}
impl AsRef<wslpluginapi_sys::WSLVersion> for WSLVersion {
#[inline]
fn as_ref(&self) -> &wslpluginapi_sys::WSLVersion {
&self.0
}
}
impl Default for WSLVersion {
#[inline]
fn default() -> Self {
Self::new(1, 0, 0)
}
}
impl Display for WSLVersion {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{}.{}", self.major(), self.minor(), self.revision())
}
}
impl Debug for WSLVersion {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct(stringify!(WSLVersion))
.field("major", &self.major())
.field("minor", &self.minor())
.field("revision", &self.revision())
.finish()
}
}