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.
§Errors
This method will return an error if the current directory cannot be determined. It will also return an error if the current directory cannot be changed.
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.
If 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.
§Errors
This method will return an error if the current directory cannot be determined. It will also return an error if the current directory cannot be changed.
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
Pushd
was constructed withPushd::new_no_panic
, it will log the error by callinglog::warn!
. -
If the
Pushd
was constructed withPushd::new
and the error is anio::Error
and the error’sio::Error::kind
method returnsio::ErrorKind::NotFound
, it will do nothing. -
Otherwise it will panic with the error from attempting to change the current directory.