pub struct Pushd { /* private fields */ }Expand description
A Pushd changes the current directory when it’s created and returns to
the original current directory when it’s dropped.
Implementations§
source§impl Pushd
impl Pushd
sourcepub fn new<P: AsRef<Path>>(path: P) -> Result<Pushd, PushdError>
pub fn new<P: AsRef<Path>>(path: P) -> Result<Pushd, PushdError>
Constructs a new Pushd struct.
This accepts any type that implements AsRef<Path>.
The Pushd returned by this constructor will panic if it cannot
change back to its original directory when it is dropped.
This will call
log::debug! to
log the directory change.
sourcepub fn new_no_panic<P: AsRef<Path>>(path: P) -> Result<Pushd, PushdError>
pub fn new_no_panic<P: AsRef<Path>>(path: P) -> Result<Pushd, PushdError>
Constructs a new Pushd struct that will never panic.
This accepts any type that implements AsRef<Path>.
This will call
log::debug! to
log the directory change.
The Pushd created by this constructor cannot change back to the
original directory when it is dropped, then it will simply call
log::warn! instead
of panicking.
sourcepub fn pop(&mut self) -> Result<(), PushdError>
pub fn pop(&mut self) -> Result<(), PushdError>
Changes back to the original directory the first time it is called. If this method is called repeatedly it will not do anything on subsequent calls.
Trait Implementations§
source§impl Drop for Pushd
impl Drop for Pushd
source§fn drop(&mut self)
fn drop(&mut self)
Changes back to the original directory.
When the Pushd struct is dropped, it will change back to the
original directory. If this fails, it’s behavior is as follows:
-
If the
Pushdwas constructed withnew_no_panic, it will log the error by callinglog::warn!. -
If the
Pushdwas constructed withnewand the error is anio::Errorand the error’sio::Error::kindmethod returnsio::ErrorKind::NotFound, it will do nothing. -
Otherwise it will panic with the error from attempting to change the current directory.