Struct Pushd

Source
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

Source

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.

Source

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.

Source

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.

§Errors

This method return an error if the current directory cannot be changed.

Trait Implementations§

Source§

impl Drop for Pushd

Source§

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:

Auto Trait Implementations§

§

impl Freeze for Pushd

§

impl RefUnwindSafe for Pushd

§

impl Send for Pushd

§

impl Sync for Pushd

§

impl Unpin for Pushd

§

impl UnwindSafe for Pushd

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.