Allow retrieving and setting prefix of VarBuilder (#699)

This commit is contained in:
Lennard
2023-09-01 09:08:41 +02:00
committed by GitHub
parent 30a4b593d7
commit 9736236175

View File

@ -102,6 +102,20 @@ impl<'a, B: Backend> VarBuilderArgs<'a, B> {
}
}
/// Returns the prefix of the `VarBuilder`.
pub fn prefix(&self) -> String {
self.path.join(".")
}
/// Returns a new `VarBuilder` with the prefix set to `prefix`.
pub fn set_prefix(&self, prefix: impl ToString) -> Self {
Self {
data: self.data.clone(),
path: vec![prefix.to_string()],
_phantom: std::marker::PhantomData,
}
}
/// Return a new `VarBuilder` adding `s` to the current prefix. This can be think of as `cd`
/// into a directory.
pub fn push_prefix<S: ToString>(&self, s: S) -> Self {