aboutsummaryrefslogtreecommitdiff
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-08 09:20:50 -0800
commitaa1f893dbe2f48c7a643c15db35802440664f60b (patch)
treea94545cd12597bd3d10b8f97eaac03ddd3555821
parent0aad1c4fe42e4c550a4a6225743d184b85618518 (diff)
downloadnitrocli-aa1f893dbe2f48c7a643c15db35802440664f60b.tar.gz
nitrocli-aa1f893dbe2f48c7a643c15db35802440664f60b.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.
-rw-r--r--nitrocli/src/arg_util.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/nitrocli/src/arg_util.rs b/nitrocli/src/arg_util.rs
index b98aa34..075dc6d 100644
--- a/nitrocli/src/arg_util.rs
+++ b/nitrocli/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
+ }
+ }
};
}