Skip to content

Commit

Permalink
Support trailing commas in all exported macros
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtriplett committed Jan 17, 2021
1 parent a6631b5 commit 192d2e0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/consts/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ macro_rules! impl_var {
$( #[cfg($meta:meta)] )*
$var:ident => $val:expr
),*
$(,)?
) => (
$(#[$outer])*
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
Expand Down Expand Up @@ -209,6 +210,7 @@ macro_rules! impl_trait {
)*
$vis_enum:vis $wrapper_type:ident,
$( $const_enum:ident ),+
$(,)?
) => {
$(#[$outer])*
$vis_trait trait $trait_name: $crate::Nl
Expand Down Expand Up @@ -332,7 +334,7 @@ macro_rules! impl_trait {
/// `u16`s and bitwise or-ed.
#[macro_export]
macro_rules! impl_flags {
($(#[$outer:meta])* $vis:vis $name:ident, $type:ty, $bin_type:ty) => {
($(#[$outer:meta])* $vis:vis $name:ident, $type:ty, $bin_type:ty $(,)?) => {
#[derive(Debug, PartialEq)]
$(#[$outer])*
$vis struct $name($crate::types::FlagBuffer::<$type>);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ lazy_static! {
#[cfg(feature = "logging")]
#[macro_export]
macro_rules! log {
($fmt:tt, $($args:expr),*) => {
($fmt:tt, $($args:expr),* $(,)?) => {
if *$crate::LOGGING_INITIALIZED && *$crate::SHOW_LOGS {
log::debug!(concat!($fmt, "\n{}"), $($args),*, ["-"; 80].join(""));
} else {
Expand Down
20 changes: 10 additions & 10 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/// ```
#[macro_export]
macro_rules! drive_serialize {
($to_ser:expr, $buffer:expr, $pos:expr) => {{
($to_ser:expr, $buffer:expr, $pos:expr $(,)?) => {{
let size = $crate::Nl::size($to_ser);
if $pos + size > $buffer.len() {
return Err($crate::err::SerError::UnexpectedEOB);
Expand All @@ -28,7 +28,7 @@ macro_rules! drive_serialize {
Err(e) => return Err(e),
}
}};
($to_ser:expr, $buffer:expr, $pos:expr, $size:ident) => {{
($to_ser:expr, $buffer:expr, $pos:expr, $size:ident $(,)?) => {{
let size = $crate::Nl::$size($to_ser);
if $pos + size > $buffer.len() {
return Err($crate::err::SerError::UnexpectedEOB);
Expand All @@ -39,7 +39,7 @@ macro_rules! drive_serialize {
Err(e) => return Err(e),
}
}};
(PAD $self:expr, $buffer:expr, $pos:expr) => {{
(PAD $self:expr, $buffer:expr, $pos:expr $(,)?) => {{
let size = $crate::Nl::asize($self) - $crate::Nl::size($self);
if $pos + size > $buffer.len() {
return Err($crate::err::SerError::UnexpectedEOB);
Expand All @@ -49,7 +49,7 @@ macro_rules! drive_serialize {
Err(e) => return Err(e),
}
}};
(END $buffer:expr, $pos:expr) => {{
(END $buffer:expr, $pos:expr $(,)?) => {{
if $buffer.len() != $pos {
return Err($crate::err::SerError::BufferNotFilled);
}
Expand Down Expand Up @@ -168,7 +168,7 @@ macro_rules! deserialize_type_size {
/// ```
#[macro_export]
macro_rules! drive_deserialize {
($de_type:ty, $buffer:expr, $pos:expr) => {{
($de_type:ty, $buffer:expr, $pos:expr $(,)?) => {{
let size = $crate::deserialize_type_size!($de_type => type_size);
if $pos + size > $buffer.len() {
return Err($crate::err::DeError::UnexpectedEOB);
Expand All @@ -177,7 +177,7 @@ macro_rules! drive_deserialize {
let t = <$de_type as $crate::Nl>::deserialize(subbuffer)?;
(t, $pos + size)
}};
($de_type:ty, $buffer:expr, $pos:expr, $size:expr) => {{
($de_type:ty, $buffer:expr, $pos:expr, $size:expr $(,)?) => {{
let size = $size;
if $pos + size > $buffer.len() {
return Err($crate::err::DeError::UnexpectedEOB);
Expand All @@ -186,14 +186,14 @@ macro_rules! drive_deserialize {
let t = <$de_type as $crate::Nl>::deserialize(&subbuffer)?;
(t, $pos + size)
}};
(STRIP $buffer:expr, $pos:expr, $size:expr) => {{
(STRIP $buffer:expr, $pos:expr, $size:expr $(,)?) => {{
let size = $size;
if $pos + size > $buffer.len() {
return Err($crate::err::DeError::UnexpectedEOB);
}
$pos + size
}};
(END $buffer:expr, $pos:expr) => {{
(END $buffer:expr, $pos:expr $(,)?) => {{
if $buffer.len() != $pos {
return Err($crate::err::DeError::BufferNotParsed);
}
Expand Down Expand Up @@ -229,7 +229,7 @@ macro_rules! drive_deserialize {
#[macro_export]
macro_rules! deserialize {
(STRIP $self_de_type:ident; $buffer:expr; $struct_type:path {
$($de_name:ident: $de_type:ty $(=> $size:expr)?),*
$($de_name:ident: $de_type:ty $(=> $size:expr)?),* $(,)?
} => $struct_size:expr) => {{
let pos = 0;
$(
Expand All @@ -244,7 +244,7 @@ macro_rules! deserialize {
}
}};
($buffer:expr; $struct_type:path {
$($de_name:ident: $de_type:ty $(=> $size:expr)?),*
$($de_name:ident: $de_type:ty $(=> $size:expr)?),* $(,)?
}) => {{
let pos = 0;
$(
Expand Down

0 comments on commit 192d2e0

Please sign in to comment.