Added try_from
& into
methods to Resolution
and WineLang
This commit is contained in:
parent
82d276d35d
commit
f035959ffd
2 changed files with 58 additions and 3 deletions
|
@ -30,6 +30,28 @@ impl From<&JsonValue> for WineLang {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u32> for WineLang {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
0 => Ok(Self::System),
|
||||
1 => Ok(Self::English),
|
||||
2 => Ok(Self::Russian),
|
||||
3 => Ok(Self::German),
|
||||
4 => Ok(Self::Portuguese),
|
||||
5 => Ok(Self::Polish),
|
||||
6 => Ok(Self::French),
|
||||
7 => Ok(Self::Spanish),
|
||||
8 => Ok(Self::Chinese),
|
||||
9 => Ok(Self::Japanese),
|
||||
10 => Ok(Self::Korean),
|
||||
|
||||
_ => Err(String::from("Failed to convert number to WineLang enum"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::from_over_into)]
|
||||
impl Into<u32> for WineLang {
|
||||
fn into(self) -> u32 {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum Resolution {
|
||||
Custom(u64, u64),
|
||||
|
||||
// qHD; 960x540
|
||||
MiniHD,
|
||||
|
||||
|
@ -13,14 +15,13 @@ pub enum Resolution {
|
|||
QuadHD,
|
||||
|
||||
// 3840x2160
|
||||
UltraHD,
|
||||
|
||||
Custom(u64, u64)
|
||||
UltraHD
|
||||
}
|
||||
|
||||
impl Resolution {
|
||||
pub fn list() -> Vec<Self> {
|
||||
vec![
|
||||
Self::Custom(0, 0),
|
||||
Self::MiniHD,
|
||||
Self::HD,
|
||||
Self::FullHD,
|
||||
|
@ -54,6 +55,38 @@ impl Resolution {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u32> for Resolution {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
0 => Ok(Self::Custom(0, 0)),
|
||||
1 => Ok(Self::MiniHD),
|
||||
2 => Ok(Self::HD),
|
||||
3 => Ok(Self::FullHD),
|
||||
4 => Ok(Self::QuadHD),
|
||||
5 => Ok(Self::UltraHD),
|
||||
|
||||
_ => Err(String::from("Failed to convert number to Resolution enum"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::from_over_into)]
|
||||
impl Into<u32> for Resolution {
|
||||
fn into(self) -> u32 {
|
||||
match self {
|
||||
Self::MiniHD => 1,
|
||||
Self::HD => 2,
|
||||
Self::FullHD => 3,
|
||||
Self::QuadHD => 4,
|
||||
Self::UltraHD => 5,
|
||||
|
||||
_ => 0 // Custom resolution
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Resolution {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let (w, h) = self.get_pair();
|
||||
|
|
Loading…
Reference in a new issue