aboutsummaryrefslogtreecommitdiffstats
path: root/src/macros.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/macros.rs')
-rw-r--r--src/macros.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/macros.rs b/src/macros.rs
new file mode 100644
index 0000000..836be63
--- /dev/null
+++ b/src/macros.rs
@@ -0,0 +1,35 @@
+#[macro_escape]
+macro_rules! notmuch_enum {
+ (
+ $(#[$enum_attr:meta])*
+ pub enum $name:ident => $name_alias:ident {
+ $($variant:ident => $variant_alias:ident),*
+ }
+ ) => {
+ $(#[$enum_attr])*
+ pub enum $name {
+ $($variant),*
+ }
+
+ $(#[$enum_attr])*
+ pub enum $name_alias {
+ $($variant_alias),*
+ }
+
+ impl NotmuchEnum for $name_alias {
+ type NotmuchT = $name;
+
+ fn from_notmuch_t(notmuch_t: $name) -> Self {
+ match notmuch_t {
+ $($name::$variant => $name_alias::$variant_alias),*
+ }
+ }
+
+ fn to_notmuch_t(self) -> $name {
+ match self {
+ $($name_alias::$variant_alias => $name::$variant),*
+ }
+ }
+ }
+ }
+}