Skip to content

Commit

Permalink
metrics: datapoint macro: Allow trailing comma (solana-labs#30317)
Browse files Browse the repository at this point in the history
Rust grammar allows trailing commas in most places where a list of
elements are accepted.  It simplifies cases when the list is generated
by a macro, allowing the macro to avoid special cases for a one element
list vs longer lists.

As such, it is a common practice to allow trailing commas in macros as
well.
  • Loading branch information
ilya-bobyr authored Mar 17, 2023
1 parent 6dd5a22 commit c449a15
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions metrics/src/datapoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ macro_rules! create_datapoint {
$crate::create_datapoint!(@tag $point $tag_name, $tag_value);
$crate::create_datapoint!(@fields $point $($rest)*);
};
(@fields $point:ident $tag_name:expr => $tag_value:expr) => {
(@fields $point:ident $tag_name:expr => $tag_value:expr $(,)?) => {
$crate::create_datapoint!(@tag $point $tag_name, $tag_value);
};

Expand All @@ -134,7 +134,7 @@ macro_rules! create_datapoint {
$crate::create_datapoint!(@field $point $name, $value, $type);
$crate::create_datapoint!(@fields $point $($rest)*);
};
(@fields $point:ident ($name:expr, $value:expr, $type:ident)) => {
(@fields $point:ident ($name:expr, $value:expr, $type:ident) $(,)?) => {
$crate::create_datapoint!(@field $point $name, $value, $type);
};

Expand All @@ -145,14 +145,14 @@ macro_rules! create_datapoint {
point
}
};
(@point $name:expr) => {
(@point $name:expr $(,)?) => {
$crate::datapoint::DataPoint::new(&$name)
};
}

#[macro_export]
macro_rules! datapoint {
($level:expr, $name:expr) => {
($level:expr, $name:expr $(,)?) => {
if log::log_enabled!($level) {
$crate::submit($crate::create_datapoint!(@point $name), $level);
}
Expand All @@ -165,7 +165,7 @@ macro_rules! datapoint {
}
#[macro_export]
macro_rules! datapoint_error {
($name:expr) => {
($name:expr $(,)?) => {
$crate::datapoint!(log::Level::Error, $name);
};
($name:expr, $($fields:tt)+) => {
Expand All @@ -175,7 +175,7 @@ macro_rules! datapoint_error {

#[macro_export]
macro_rules! datapoint_warn {
($name:expr) => {
($name:expr $(,)?) => {
$crate::datapoint!(log::Level::Warn, $name);
};
($name:expr, $($fields:tt)+) => {
Expand Down

0 comments on commit c449a15

Please sign in to comment.