feat: xrservicetype to/from string and iter

This commit is contained in:
Gabriele Musco 2023-06-24 12:48:42 +02:00
commit e2a76133d6
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE

View file

@ -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,