CwdGuard

Struct CwdGuard 

Source
pub struct CwdGuard<'lock> { /* private fields */ }
Expand description

A version of Cwd that will reset() the current working directory to it’s previous state on drop().

reset() can be called manually to handle errors or automatically on drop().

Implementations§

Source§

impl CwdGuard<'_>

Source

pub fn reset(&mut self) -> Result<()>

Resets the current working directory to the initial current working directory at the time of selfs creation.

§Errors

The current directory cannot be set as per env::set_current_dir()

Methods from Deref<Target = Cwd>§

Source

pub fn get_expected(&self) -> Option<PathBuf>

Returns the expected current working directory if any. By default the only expectations set are when this crate produces a panic.

Source

pub fn get(&self) -> Result<PathBuf>

Wrapper function to ensure env::current_dir() is called with the Cwd borrowed.

Source

pub fn set<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Wrapper function to ensure env::set_current_dir() is called with the Cwd borrowed.

Trait Implementations§

Source§

impl Deref for CwdGuard<'_>

Source§

type Target = Cwd

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for CwdGuard<'_>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Drop for CwdGuard<'_>

Source§

fn drop(&mut self)

§Panics

If the current directory cannot be reset()

Source§

impl<'lock> TryFrom<&'lock mut Cwd> for CwdGuard<'lock>

Source§

fn try_from(cwd: &'lock mut Cwd) -> Result<Self, Self::Error>

Creates a CwdGuard mutably borrowing the locked Self.

§Errors

The current directory cannot be retrieved as per env::current_dir()

Source§

type Error = Error

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

impl<'lock> TryFrom<&'lock mut CwdGuard<'_>> for CwdGuard<'lock>

Source§

fn try_from(cwd_guard: &'lock mut CwdGuard<'_>) -> Result<Self, Self::Error>

Create a new CwdGuard under cwd_guard that will reset() to cwd_guard when drop() is called.

§Errors

The current directory cannot be retrieved as per env::current_dir()

Source§

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl<'lock> Freeze for CwdGuard<'lock>

§

impl<'lock> !RefUnwindSafe for CwdGuard<'lock>

§

impl<'lock> Send for CwdGuard<'lock>

§

impl<'lock> !Sync for CwdGuard<'lock>

§

impl<'lock> Unpin for CwdGuard<'lock>

§

impl<'lock> !UnwindSafe for CwdGuard<'lock>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.