pub struct CwdGuard { /* private fields */ }Expand description
Guard that temporarily changes the current working directory and restores the previous one on drop.
This guard is useful for testing or temporarily changing the working directory in a controlled manner. When the guard is dropped, it automatically restores the previous working directory.
§Error Handling
If restoring the previous directory fails during drop, the error is silently ignored
(logged via let _ = ...). This is intentional to avoid panicking in destructors.
§Examples
use std::path::Path;
use xet_runtime::utils::CwdGuard;
// Temporarily change to a different directory
let new_dir = Path::new("/tmp");
let _guard = CwdGuard::set(new_dir)?;
// Current working directory is changed here
// When _guard is dropped, the previous directory is restoredImplementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CwdGuard
impl RefUnwindSafe for CwdGuard
impl Send for CwdGuard
impl Sync for CwdGuard
impl Unpin for CwdGuard
impl UnsafeUnpin for CwdGuard
impl UnwindSafe for CwdGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more