0

I have a set of Cargo crates in a workspace which is structured as below:

project1
|- app-context
|  |- src/lib.rs
|  |- Cargo.toml
|- config
|  |-development.toml
|Cargo.toml

I am running a function in lib.rs using rust tests which print the folders and files in the folder using

let paths = fs::read_dir("./").unwrap();

for path in paths {
    println!("Name: {}", path.unwrap().path().display())
}

The output I get is src & Cargo.toml. But the result I expect is app-context & config. What am I doing wrong here? How do I set the default working directory to the folder containing all my crates rather than pointing to a particular workspace?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Asnim P Ansari
  • 1,932
  • 1
  • 18
  • 41
  • 1
    I have fixed the nomenclature in the question, please check whether this is what you originally intended. The directories inside `project1` represent _crates_, whereas a _workspace_ is what you have at the root level. – E_net4 Apr 27 '20 at 13:35
  • 1
    It looks like your question might be answered by the answers of [How can I locate resources for testing with Cargo?](https://stackoverflow.com/q/30003921/155423). If not, please **[edit]** your question to explain the differences. Otherwise, we can mark this question as already answered. – Shepmaster Apr 27 '20 at 13:43

0 Answers0