Use strum for constructor
This commit is contained in:
parent
97d523a149
commit
4781506ff9
@ -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 {
|
pub enum Parameters {
|
||||||
Collide(CollideParams),
|
Collide(CollideParams),
|
||||||
Slide(SlideParams),
|
Slide(SlideParams),
|
||||||
@ -153,21 +153,6 @@ impl FormRender for Parameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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] {
|
pub const fn get_names() -> &'static [&'static str] {
|
||||||
&[
|
&[
|
||||||
"Solid",
|
"Solid",
|
||||||
|
@ -4,6 +4,7 @@ use actix_web_actors::ws;
|
|||||||
use common::{error, pattern, strip};
|
use common::{error, pattern, strip};
|
||||||
use live_view::{LiveView, StateSocket, Template};
|
use live_view::{LiveView, StateSocket, Template};
|
||||||
use template::{AppTemplate, ControlTemplate};
|
use template::{AppTemplate, ControlTemplate};
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
error::{ErrorInternalServerError, JsonPayloadError, UrlencodedError},
|
error::{ErrorInternalServerError, JsonPayloadError, UrlencodedError},
|
||||||
@ -100,7 +101,7 @@ async fn start_socket(
|
|||||||
println!("Got change template event: {event:?}");
|
println!("Got change template event: {event:?}");
|
||||||
|
|
||||||
let template_name = event.data.as_ref()?;
|
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.parameters = params;
|
||||||
state
|
state
|
||||||
|
Loading…
Reference in New Issue
Block a user