From 5b8e5066a0f217e7b68ed6b60327d53d4df56de1 Mon Sep 17 00:00:00 2001 From: Wei <47681251+QuenKar@users.noreply.github.com> Date: Wed, 18 Oct 2023 14:32:50 +0800 Subject: [PATCH] refactor: make ReadableSize more readable. (#2614) * refactor: ReadableSize is readable. * docs: Update src/common/base/src/readable_size.rs --------- Co-authored-by: Yingwen --- src/common/base/src/readable_size.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/common/base/src/readable_size.rs b/src/common/base/src/readable_size.rs index ef25eab5f1..100d0f56a8 100644 --- a/src/common/base/src/readable_size.rs +++ b/src/common/base/src/readable_size.rs @@ -14,10 +14,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -// This file is copied from https://github.com/tikv/raft-engine/blob/8dd2a39f359ff16f5295f35343f626e0c10132fa/src/util.rs without any modification. +// This file is copied from https://github.com/tikv/raft-engine/blob/8dd2a39f359ff16f5295f35343f626e0c10132fa/src/util.rs -use std::fmt; -use std::fmt::{Display, Write}; +use std::fmt::{self, Debug, Display, Write}; use std::ops::{Div, Mul}; use std::str::FromStr; @@ -34,7 +33,7 @@ pub const GIB: u64 = MIB * BINARY_DATA_MAGNITUDE; pub const TIB: u64 = GIB * BINARY_DATA_MAGNITUDE; pub const PIB: u64 = TIB * BINARY_DATA_MAGNITUDE; -#[derive(Clone, Debug, Copy, PartialEq, Eq, PartialOrd)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd)] pub struct ReadableSize(pub u64); impl ReadableSize { @@ -155,6 +154,12 @@ impl FromStr for ReadableSize { } } +impl Debug for ReadableSize { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self) + } +} + impl Display for ReadableSize { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.0 >= PIB {