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