summaryrefslogtreecommitdiff
path: root/src/arg_util.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2020-01-07 13:07:15 +0000
committerDaniel Mueller <deso@posteo.net>2020-01-07 13:07:15 +0000
commitddd34824b79d1af1b40d6a01509842d0b4d648ea (patch)
treebdacc7ac6925f08b643aecbc444f4f1da256681c /src/arg_util.rs
parent971b6c22a7f3d70840ca373bc54fcdae1f86262a (diff)
downloadnitrocli-ddd34824b79d1af1b40d6a01509842d0b4d648ea.tar.gz
nitrocli-ddd34824b79d1af1b40d6a01509842d0b4d648ea.tar.bz2
Implement Default in the Enum! and Command! macros
For the transition to structopt, we have to be able to easily construct enum variants once we have added fields to them. Therefore we implement the Default trait in the generated macros by choosing the first variant as the default.
Diffstat (limited to 'src/arg_util.rs')
-rw-r--r--src/arg_util.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/arg_util.rs b/src/arg_util.rs
index 06a6ee6..d54dd94 100644
--- a/src/arg_util.rs
+++ b/src/arg_util.rs
@@ -76,6 +76,8 @@ macro_rules! Command {
}
}
}
+
+ impl_default!($name => $( $name::$var(::std::default::Default::default()) , )*);
};
( $name:ident, [ $( $var:ident => ($str:expr, $exec:expr), ) *] ) => {
#[derive(Debug, PartialEq)]
@@ -128,6 +130,8 @@ macro_rules! Command {
}
}
}
+
+ impl_default!($name => $( $name::$var , )*);
};
}
@@ -204,6 +208,19 @@ macro_rules! enum_int {
}
}
}
+
+ impl_default!($name => $( $name::$var , )*);
+
+ };
+}
+
+macro_rules! impl_default {
+ ( $name:ident => $def:expr , $( $other:expr , ) *) => {
+ impl ::std::default::Default for $name {
+ fn default() -> Self {
+ $def
+ }
+ }
};
}