diff --git a/src/macros.rs b/src/macros.rs index 395230b4..51bb95a7 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -345,6 +345,14 @@ macro_rules! arg_enum { } }); }; + ($(#[$($m:meta),+])+ pub enum $e:ident { $($v:ident $(=$val:expr)*,)+ } ) => { + arg_enum!(@impls + ($(#[$($m),+])+ + pub enum $e { + $($v$(=$val)*),+ + }) -> ($e, $($v),+) + ); + }; ($(#[$($m:meta),+])+ pub enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => { arg_enum!(@impls ($(#[$($m),+])+ @@ -353,7 +361,14 @@ macro_rules! arg_enum { }) -> ($e, $($v),+) ); }; - ($(#[$($m:meta),+])+ enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => { + ($(#[$($m:meta),+])+ enum $e:ident { $($v:ident $(=$val:expr)*,)+ } ) => { + arg_enum!($(#[$($m:meta),+])+ + enum $e:ident { + $($v:ident $(=$val:expr)*),+ + } + ); + }; + ($(#[$($m:meta),+])+ enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => { arg_enum!(@impls ($(#[$($m),+])+ enum $e { @@ -361,6 +376,11 @@ macro_rules! arg_enum { }) -> ($e, $($v),+) ); }; + (pub enum $e:ident { $($v:ident $(=$val:expr)*,)+ } ) => { + arg_enum!(pub enum $e:ident { + $($v:ident $(=$val:expr)*),+ + }); + }; (pub enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => { arg_enum!(@impls (pub enum $e { @@ -368,6 +388,11 @@ macro_rules! arg_enum { }) -> ($e, $($v),+) ); }; + (enum $e:ident { $($v:ident $(=$val:expr)*,)+ } ) => { + arg_enum!(enum $e:ident { + $($v:ident $(=$val:expr)*),+ + }); + }; (enum $e:ident { $($v:ident $(=$val:expr)*),+ } ) => { arg_enum!(@impls (enum $e { diff --git a/tests/macros.rs b/tests/macros.rs index ae20e27b..fec61132 100644 --- a/tests/macros.rs +++ b/tests/macros.rs @@ -159,3 +159,15 @@ fn arg_enum() { } assert_eq!("Alpha".parse::(), Ok(Greek::Alpha)); } + +#[test] +fn arg_enum_trailing_comma() { + arg_enum!{ + #[derive(Debug, PartialEq, Copy, Clone)] + pub enum Greek { + Alpha, + Bravo, + } + } + assert_eq!("Alpha".parse::(), Ok(Greek::Alpha)); +}