#cwd #with-cwd

with_dir

Scoped current working directory

5 releases

0.1.4 Mar 17, 2023
0.1.3 Mar 16, 2023
0.1.2 Mar 15, 2023
0.1.1 Mar 15, 2023
0.1.0 Mar 15, 2023

#1141 in Filesystem

49 downloads per month

Custom license

11KB
188 lines

with_dir

Blazingly fast utility library for temporarily changing the current working directory.

This library provides the following features:

  1. Convenient scoped changing of directories
  2. Global Reentrant mutex to prevent concurrent instances of WithDir from conflicting.

The mutex allows this to be safely used across multhreaded tests, where each test will be entering different directories as no two WithDir instances can exist on different threads. However nested instances on the same thread can exist.

use with_dir::WithDir;
use std::path::Path;

let path = Path::new("src");

// enter that directory
WithDir::new(path).map(|_| {
    // Current working directory is now src
}).unwrap();
// cwd is reset

Contributing

Contributions welcome.

FAQ

Is it good?

yes.

License

See LICENSE


lib.rs:

Library provides the struct WithDir which uses RAII to enable scoped change of working directory. See docs for WithDir for simple example.

Dependencies

~2–10MB
~113K SLoC