Skip to content

Commit 07d7fa5

Browse files
committed
fix: expose append-only methods to the guard
1 parent d7d811a commit 07d7fa5

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

storage/src/path/buf.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ impl<'a> IntoSplitPath for &'a PartialPath<'_> {
130130
}
131131

132132
/// A RAII guard that resets a path buffer to its original length when dropped.
133+
///
134+
/// The guard exposes append-only methods to add components to the path buffer
135+
/// but not remove them without dropping the guard. This ensures that the guard
136+
/// will always restore the path buffer to its original state when dropped.
133137
#[must_use]
134138
pub struct PathGuard<'a> {
135139
buf: &'a mut PathBuf,
@@ -178,6 +182,13 @@ impl<'a> PathGuard<'a> {
178182
fork.extend(path.components());
179183
fork
180184
}
185+
186+
/// Appends the given component to the path buffer.
187+
///
188+
/// This component will be removed when the guard is dropped.
189+
pub fn push(&mut self, component: PathComponent) {
190+
self.buf.push(component);
191+
}
181192
}
182193

183194
impl std::ops::Deref for PathGuard<'_> {
@@ -188,8 +199,8 @@ impl std::ops::Deref for PathGuard<'_> {
188199
}
189200
}
190201

191-
impl std::ops::DerefMut for PathGuard<'_> {
192-
fn deref_mut(&mut self) -> &mut Self::Target {
193-
self.buf
202+
impl Extend<PathComponent> for PathGuard<'_> {
203+
fn extend<T: IntoIterator<Item = PathComponent>>(&mut self, iter: T) {
204+
self.buf.extend(iter);
194205
}
195206
}

0 commit comments

Comments
 (0)