From 874acb70390fef4079cb080175dcbe67d2d53474 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 13 Mar 2019 09:57:36 +0100 Subject: [PATCH] src/client/backup_repo.rs: implement Display trait --- src/client/backup_repo.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/client/backup_repo.rs b/src/client/backup_repo.rs index 1a90a36d..64cd9866 100644 --- a/src/client/backup_repo.rs +++ b/src/client/backup_repo.rs @@ -5,6 +5,7 @@ use crate::api_schema::*; use std::sync::Arc; use lazy_static::lazy_static; use regex::Regex; +use std::fmt; lazy_static! { /// Regular expression to parse repository URLs @@ -68,15 +69,16 @@ impl BackupRepository { pub fn store(&self) -> &str { &self.store } - - pub fn to_string(&self) -> String { - - if let Some(ref user) = self.user { - return format!("{}@{}:{}", user, self.host(), self.store); - } else if let Some(ref host) = self.host { - return format!("{}:{}", host, self.store); - } - self.store.to_owned() - } - +} + +impl fmt::Display for BackupRepository { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + if let Some(ref user) = self.user { + write!(f, "{}@{}:{}", user, self.host(), self.store) + } else if let Some(ref host) = self.host { + write!(f, "{}:{}", host, self.store) + } else { + write!(f, "{}", self.store) + } + } }