From 2c593cd38c5dc13779892ce75afcdd0c65452a50 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Thu, 28 Apr 2022 09:37:10 +0200 Subject: [PATCH] api types: BackupNamespace add pop & parent helpers Signed-off-by: Thomas Lamprecht --- pbs-api-types/src/datastore.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs index f78c7f26..32558066 100644 --- a/pbs-api-types/src/datastore.rs +++ b/pbs-api-types/src/datastore.rs @@ -563,6 +563,25 @@ impl BackupNamespace { Ok(child) } + /// Pop one level off the namespace hierachy + pub fn pop(&mut self) { + if let Some(dropped) = self.inner.pop() { + self.len = self.len.saturating_sub(dropped.len() + 1); + } + } + + /// Get the namespace parent as owned BackupNamespace + pub fn parent(&self) -> Self { + if self.is_root() { + return Self::root(); + } + + let mut parent = self.clone(); + parent.pop(); + + parent + } + /// Create a new namespace directly from a vec. /// /// # Safety