File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff 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]
134138pub 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
183194impl 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}
You can’t perform that action at this time.
0 commit comments