From 40a57cfab07969d6018b82d4e8de50fb77b2ee60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Mon, 24 Apr 2023 15:56:26 +0200 Subject: [PATCH] pull: impl Display for SkipReason MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit instead of manually doing it in SkipInfo's Display implementation. Signed-off-by: Fabian Grünbichler --- src/server/pull.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/server/pull.rs b/src/server/pull.rs index e50037ed..a973a10e 100644 --- a/src/server/pull.rs +++ b/src/server/pull.rs @@ -540,11 +540,25 @@ async fn pull_snapshot_from( Ok(()) } +#[derive(PartialEq, Eq)] enum SkipReason { AlreadySynced, TransferLast, } +impl std::fmt::Display for SkipReason { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + SkipReason::AlreadySynced => "older than the newest local snapshot", + SkipReason::TransferLast => "due to transfer-last", + } + ) + } +} + struct SkipInfo { oldest: i64, newest: i64, @@ -595,17 +609,12 @@ impl SkipInfo { impl std::fmt::Display for SkipInfo { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let reason_string = match self.skip_reason { - SkipReason::AlreadySynced => "older than the newest local snapshot", - SkipReason::TransferLast => "due to transfer-last", - }; - write!( f, "skipped: {} snapshot(s) ({}) - {}", self.count, self.affected().map_err(|_| std::fmt::Error)?, - reason_string + self.skip_reason, ) } }