From 2f550efced089d96f654d9b93b2481cf3f6ae738 Mon Sep 17 00:00:00 2001 From: QuenKar <47681251+QuenKar@users.noreply.github.com> Date: Wed, 18 Oct 2023 10:20:52 +0800 Subject: [PATCH 1/2] refactor: ReadableSize is readable. --- src/common/base/src/readable_size.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/base/src/readable_size.rs b/src/common/base/src/readable_size.rs index ef25eab5f1e4..ef9206439bb5 100644 --- a/src/common/base/src/readable_size.rs +++ b/src/common/base/src/readable_size.rs @@ -16,8 +16,7 @@ // This file is copied from https://github.com/tikv/raft-engine/blob/8dd2a39f359ff16f5295f35343f626e0c10132fa/src/util.rs without any modification. -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 { From 36b6b5ba5b14e2bc6055f156b8a589e5f2bef608 Mon Sep 17 00:00:00 2001 From: Yingwen Date: Wed, 18 Oct 2023 14:21:25 +0800 Subject: [PATCH 2/2] docs: Update src/common/base/src/readable_size.rs --- src/common/base/src/readable_size.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/base/src/readable_size.rs b/src/common/base/src/readable_size.rs index ef9206439bb5..100d0f56a801 100644 --- a/src/common/base/src/readable_size.rs +++ b/src/common/base/src/readable_size.rs @@ -14,7 +14,7 @@ // 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::{self, Debug, Display, Write}; use std::ops::{Div, Mul};