From e2a76133d6f808606dba3412c6ff14fa344f62a9 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Sat, 24 Jun 2023 12:48:42 +0200 Subject: [PATCH] feat: xrservicetype to/from string and iter --- src/profile.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/profile.rs b/src/profile.rs index 486d3f1..7cedd8f 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -4,7 +4,7 @@ use crate::{ }; use expect_dialog::ExpectDialog; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, fmt::Display, fs::File, io::BufReader}; +use std::{collections::HashMap, fmt::Display, fs::File, io::BufReader, slice::Iter}; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum XRServiceType { @@ -12,6 +12,29 @@ pub enum XRServiceType { Wivrn, } +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, XRServiceType> { + [Self::Monado, Self::Wivrn].iter() + } +} + +impl Display for XRServiceType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + Self::Monado => "Monado", + Self::Wivrn => "WiVRn", + }) + } +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Profile { pub name: String,