diff --git a/src/profile.rs b/src/profile.rs index a1a49c4..255ec84 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -21,33 +21,10 @@ pub enum XRServiceType { } impl XRServiceType { - pub fn from_string(s: String) -> Self { - match s.trim().to_lowercase().as_str() { - "monado" => Self::Monado, - "wivrn" => Self::Wivrn, - _ => Self::Monado, - } - } - pub fn iter() -> Iter<'static, Self> { [Self::Monado, Self::Wivrn].iter() } - pub fn as_number(&self) -> u32 { - match self { - Self::Monado => 0, - Self::Wivrn => 1, - } - } - - pub fn from_number(i: u32) -> Self { - match i { - 0 => Self::Monado, - 1 => Self::Wivrn, - _ => panic!("XRServiceType index out of bounds"), - } - } - /// relative path from the prefix lib dir of the libopenxr shared object pub fn libopenxr_path(&self) -> &'static str { match self { @@ -65,6 +42,35 @@ impl XRServiceType { } } +impl From<&str> for XRServiceType { + fn from(s: &str) -> Self { + match s.trim().to_lowercase().as_str() { + "monado" => Self::Monado, + "wivrn" => Self::Wivrn, + _ => Self::Monado, + } + } +} + +impl From for XRServiceType { + fn from(i: u32) -> Self { + match i { + 0 => Self::Monado, + 1 => Self::Wivrn, + _ => panic!("XRServiceType index out of bounds"), + } + } +} + +impl Into for XRServiceType { + fn into(self) -> u32 { + match self { + Self::Monado => 0, + Self::Wivrn => 1, + } + } +} + impl Display for XRServiceType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { @@ -182,8 +188,8 @@ impl Default for LighthouseDriver { } } -impl LighthouseDriver { - pub fn from_string(s: String) -> Self { +impl From<&str> for LighthouseDriver { + fn from(s: &str) -> Self { match s.trim().to_lowercase().as_str() { "vive" => Self::Vive, "survive" => Self::Survive, @@ -193,20 +199,10 @@ impl LighthouseDriver { _ => Self::Vive, } } +} - pub fn iter() -> Iter<'static, Self> { - [Self::Vive, Self::Survive, Self::SteamVR].iter() - } - - pub fn as_number(&self) -> u32 { - match self { - Self::Vive => 0, - Self::Survive => 1, - Self::SteamVR => 2, - } - } - - pub fn from_number(i: u32) -> Self { +impl From for LighthouseDriver { + fn from(i: u32) -> Self { match i { 0 => Self::Vive, 1 => Self::Survive, @@ -216,6 +212,22 @@ impl LighthouseDriver { } } +impl Into for LighthouseDriver { + fn into(self) -> u32 { + match self { + Self::Vive => 0, + Self::Survive => 1, + Self::SteamVR => 2, + } + } +} + +impl LighthouseDriver { + pub fn iter() -> Iter<'static, Self> { + [Self::Vive, Self::Survive, Self::SteamVR].iter() + } +} + impl Display for LighthouseDriver { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(match self { diff --git a/src/ui/profile_editor.rs b/src/ui/profile_editor.rs index 19fe58c..9cfca7a 100644 --- a/src/ui/profile_editor.rs +++ b/src/ui/profile_editor.rs @@ -147,7 +147,7 @@ impl SimpleComponent for ProfileEditor { .collect::>(), clone!(#[strong] prof, move |row| { prof.borrow_mut().xrservice_type = - XRServiceType::from_number(row.selected()); + XRServiceType::from(row.selected()); }), ), add: &entry_row( @@ -171,7 +171,7 @@ impl SimpleComponent for ProfileEditor { .collect::>(), clone!(#[strong] prof, move |row| { prof.borrow_mut().lighthouse_driver = - LighthouseDriver::from_number(row.selected()); + LighthouseDriver::from(row.selected()); }) ), add: &path_row(