api: add DatastoreWithNamespace helper struct

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2022-05-05 10:58:26 +02:00 committed by Thomas Lamprecht
parent d3a570eb79
commit 40d495de6d
1 changed files with 16 additions and 0 deletions

View File

@ -1054,6 +1054,22 @@ impl fmt::Display for BackupDir {
}
}
/// Helper struct for places where sensible formatting of store+NS combo is required
pub struct DatastoreWithNamespace {
pub store: String,
pub ns: BackupNamespace,
}
impl fmt::Display for DatastoreWithNamespace {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.ns.is_root() {
write!(f, "{}", self.store)
} else {
write!(f, "{}/{}", self.store, self.ns)
}
}
}
/// Used when both a backup group or a directory can be valid.
pub enum BackupPart {
Group(BackupGroup),