From 10ce986c0fad69989983edad0ea7fc72477e9758 Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Sat, 28 Oct 2023 16:14:36 -0400 Subject: [PATCH] address review comments * replaced `crate::*` with `$crate::*` * updated the `style_edition_default!` to use a match like syntax --- src/config/style_edition.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/config/style_edition.rs b/src/config/style_edition.rs index 3a9761cd02c..4dd5f0164fa 100644 --- a/src/config/style_edition.rs +++ b/src/config/style_edition.rs @@ -9,27 +9,27 @@ pub(crate) trait StyleEditionDefault { /// macro to help implement `StyleEditionDefault` for config options #[macro_export] macro_rules! style_edition_default { - ($ty:ident, $config_ty:ty, $default:expr) => { - impl crate::config::style_edition::StyleEditionDefault for $ty { + ($ty:ident, $config_ty:ty, _ => $default:expr) => { + impl $crate::config::style_edition::StyleEditionDefault for $ty { type ConfigType = $config_ty; - fn style_edition_default(_: crate::config::StyleEdition) -> Self::ConfigType { + fn style_edition_default(_: $crate::config::StyleEdition) -> Self::ConfigType { $default } } }; - ($ty:ident, $config_ty:ty, $default_2015:expr, $default_2024:expr) => { - impl crate::config::style_edition::StyleEditionDefault for $ty { + ($ty:ident, $config_ty:ty, Edition2024 => $default_2024:expr, _ => $default_2015:expr) => { + impl $crate::config::style_edition::StyleEditionDefault for $ty { type ConfigType = $config_ty; fn style_edition_default( - style_edition: crate::config::StyleEdition, + style_edition: $crate::config::StyleEdition, ) -> Self::ConfigType { match style_edition { - crate::config::StyleEdition::Edition2015 - | crate::config::StyleEdition::Edition2018 - | crate::config::StyleEdition::Edition2021 => $default_2015, - crate::config::StyleEdition::Edition2024 => $default_2024, + $crate::config::StyleEdition::Edition2015 + | $crate::config::StyleEdition::Edition2018 + | $crate::config::StyleEdition::Edition2021 => $default_2015, + $crate::config::StyleEdition::Edition2024 => $default_2024, } } } @@ -44,7 +44,7 @@ mod test { #[test] fn test_impl_default_style_edition_struct_for_all_editions() { struct Unit; - style_edition_default!(Unit, usize, 100); + style_edition_default!(Unit, usize, _ => 100); // regardless of the style edition used the value will always return 100 assert_eq!(Unit::style_edition_default(StyleEdition::Edition2015), 100); @@ -56,7 +56,7 @@ mod test { #[test] fn test_impl_default_style_edition_for_old_and_new_editions() { struct Unit; - style_edition_default!(Unit, usize, 100, 50); + style_edition_default!(Unit, usize, Edition2024 => 50, _ => 100); // style edition 2015-2021 are all the same assert_eq!(Unit::style_edition_default(StyleEdition::Edition2015), 100);