From dd01f9c01584428debb3922d78beacb1c25bd93a Mon Sep 17 00:00:00 2001 From: Maxim Savenkov Date: Thu, 7 Sep 2023 18:28:52 +0200 Subject: [PATCH] Add option to make precision infinite --- core/src/buffer.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/core/src/buffer.rs b/core/src/buffer.rs index 240e041c2e7..44ab19c68b8 100644 --- a/core/src/buffer.rs +++ b/core/src/buffer.rs @@ -53,6 +53,11 @@ where e1 = precision; s2 = len - precision; } + } else if !f.sign_plus() { + if median > 8 { + e1 = 8; + s2 = len - 8; + } } let p1 = hex::encode(&self.0[..e1]); @@ -276,9 +281,14 @@ mod test { // `Debug`/`Display`. assert_eq!( - format!("{buffer:?}"), + format!("{buffer:+?}"), "0x6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435" ); + // `Debug`/`Display` with default precision. + assert_eq!( + format!("{buffer:?}"), + "0x6162636465666768..797a303132333435" + ); // `Debug`/`Display` with precision 0. assert_eq!(format!("{buffer:.0?}"), "0x.."); // `Debug`/`Display` with precision 1. @@ -292,14 +302,19 @@ mod test { format!("{buffer:.15?}"), "0x6162636465666768696a6b6c6d6e6f..72737475767778797a303132333435" ); - // `Debug`/`Display` with precision 30 (the same for any case >= 16). + // `Debug`/`Display` with precision 30. assert_eq!( format!("{buffer:.30?}"), "0x6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435" ); - // Alternate formatter. + // Alternate formatter with default precision. assert_eq!( format!("{buffer:#}"), + "LimitedVec(0x6162636465666768..797a303132333435)" + ); + // Alternate formatter with max precision. + assert_eq!( + format!("{buffer:+#}"), "LimitedVec(0x6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435)" ); // Alternate formatter with precision 2.