Use strum for constructor

This commit is contained in:
Austen Adler 2023-05-28 17:46:02 -04:00
parent 97d523a149
commit 4781506ff9
2 changed files with 3 additions and 17 deletions

View File

@ -117,7 +117,7 @@ impl InputRender for u16 {
}
}
#[derive(Serialize, Deserialize, Clone, Debug, strum::Display)]
#[derive(Serialize, Deserialize, Clone, Debug, strum::Display, strum::EnumString)]
pub enum Parameters {
Collide(CollideParams),
Slide(SlideParams),
@ -153,21 +153,6 @@ impl FormRender for Parameters {
}
impl Parameters {
pub fn default_with_name(name: &str) -> Option<Self> {
match name {
"Collide" => Some(Self::Collide(CollideParams::default())),
"Slide" => Some(Self::Slide(SlideParams::default())),
"Fade" => Some(Self::Fade(FadeParams::default())),
"MovingPixel" => Some(Self::MovingPixel(MovingPixelParams::default())),
"MovingRainbow" => Some(Self::MovingRainbow(MovingRainbowParams::default())),
"Orb" => Some(Self::Orb(OrbParams::default())),
"Solid" => Some(Self::Solid(SolidParams::default())),
"Visualizer" => Some(Self::Visualizer(VisualizerParams::default())),
"Flashing" => Some(Self::Flashing(FlashingParams::default())),
_ => None,
}
}
pub const fn get_names() -> &'static [&'static str] {
&[
"Solid",

View File

@ -4,6 +4,7 @@ use actix_web_actors::ws;
use common::{error, pattern, strip};
use live_view::{LiveView, StateSocket, Template};
use template::{AppTemplate, ControlTemplate};
use std::str::FromStr;
use actix_web::{
error::{ErrorInternalServerError, JsonPayloadError, UrlencodedError},
@ -100,7 +101,7 @@ async fn start_socket(
println!("Got change template event: {event:?}");
let template_name = event.data.as_ref()?;
let params = pattern::Parameters::default_with_name(template_name)?;
let params = pattern::Parameters::from_str(template_name).ok()?;
state.parameters = params;
state