From 40c147691acd4996fc6883a05734fc6da125143d Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Fri, 5 Jul 2019 16:40:21 -0700 Subject: [PATCH] fix formatting for arrays after #156 arrays shouldn't be formatted with a leading reference --- phf_shared/src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/phf_shared/src/lib.rs b/phf_shared/src/lib.rs index 1cb52750..b41a77b9 100644 --- a/phf_shared/src/lib.rs +++ b/phf_shared/src/lib.rs @@ -212,6 +212,11 @@ impl PhfHash for char { } } +// minimize duplicated code since formatting drags in quite a bit +fn fmt_array(array: &[u8], f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", array) +} + macro_rules! array_impl( ($t:ty, $n:expr) => ( impl PhfHash for [$t; $n] { @@ -223,8 +228,7 @@ macro_rules! array_impl( impl FmtConst for [$t; $n] { fn fmt_const(&self, f: &mut fmt::Formatter) -> fmt::Result { - // delegate to the slice impl to minimize duplicated code - self[..].fmt_const(f) + fmt_array(self, f) } } )