mirror of
https://github.com/ricoriedel/wipe.git
synced 2024-11-17 21:46:39 +00:00
Replace code with macro
This commit is contained in:
parent
d8fdc142e6
commit
4ff02a66fc
55
src/main.rs
55
src/main.rs
@ -35,23 +35,27 @@ mod timer;
|
||||
mod runner;
|
||||
mod choose;
|
||||
|
||||
macro_rules! options {
|
||||
($name:ident { $($opt:ident,)* }) => {
|
||||
#[derive(Copy, Clone, ArgEnum)]
|
||||
enum AnimationType {
|
||||
enum $name {
|
||||
$($opt,)*
|
||||
}
|
||||
impl Options for $name {
|
||||
fn all() -> Vec<Self> {
|
||||
vec![$($name::$opt,)*]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
options!(AnimationType {
|
||||
Circle,
|
||||
Rhombus,
|
||||
Rotation
|
||||
}
|
||||
Rotation,
|
||||
});
|
||||
|
||||
impl Options for AnimationType {
|
||||
fn all() -> Vec<Self> where Self: Sized {
|
||||
use AnimationType::*;
|
||||
|
||||
vec![Circle, Rhombus, Rotation]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, ArgEnum)]
|
||||
enum ColorType {
|
||||
options!(ColorType {
|
||||
Red,
|
||||
Green,
|
||||
Blue,
|
||||
@ -60,30 +64,13 @@ enum ColorType {
|
||||
LightBlue,
|
||||
Grey,
|
||||
Rainbow,
|
||||
}
|
||||
});
|
||||
|
||||
impl Options for ColorType {
|
||||
fn all() -> Vec<Self> where Self: Sized {
|
||||
use ColorType::*;
|
||||
|
||||
vec![Red, Green, Blue, LightRed, LightGreen, LightBlue, Grey, Rainbow]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, ArgEnum)]
|
||||
enum FillModeType {
|
||||
options!(FillModeType {
|
||||
Circle,
|
||||
Level,
|
||||
Stripes
|
||||
}
|
||||
|
||||
impl Options for FillModeType {
|
||||
fn all() -> Vec<Self> where Self: Sized {
|
||||
use FillModeType::*;
|
||||
|
||||
vec![Circle, Level]
|
||||
}
|
||||
}
|
||||
Stripes,
|
||||
});
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(author = env ! ("CARGO_PKG_AUTHORS"), version = env ! ("CARGO_PKG_VERSION"), about = env ! ("CARGO_PKG_DESCRIPTION"))]
|
||||
|
Loading…
Reference in New Issue
Block a user