pull: impl Display for SkipReason

instead of manually doing it in SkipInfo's Display implementation.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2023-04-24 15:56:26 +02:00
parent 73b53e4af5
commit 40a57cfab0

View File

@ -540,11 +540,25 @@ async fn pull_snapshot_from(
Ok(()) Ok(())
} }
#[derive(PartialEq, Eq)]
enum SkipReason { enum SkipReason {
AlreadySynced, AlreadySynced,
TransferLast, 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 { struct SkipInfo {
oldest: i64, oldest: i64,
newest: i64, newest: i64,
@ -595,17 +609,12 @@ impl SkipInfo {
impl std::fmt::Display for SkipInfo { impl std::fmt::Display for SkipInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 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!( write!(
f, f,
"skipped: {} snapshot(s) ({}) - {}", "skipped: {} snapshot(s) ({}) - {}",
self.count, self.count,
self.affected().map_err(|_| std::fmt::Error)?, self.affected().map_err(|_| std::fmt::Error)?,
reason_string self.skip_reason,
) )
} }
} }