0

I'm writing a Rust library called my_new_lib and have the following file structure:

├── my_new_lib
    ├── src
        ├── lib.rs
        └── file1.rs
    ├── tests

In lib.rs I defined a struct:

/// content of lib.rs

pub struct my_struct {}

In file1.rs I want to use my_struct, for example:

/// content of file1.rs

use ????

pub struct my_second_struct {
    member1: my_struct
}

what should I put in the use clause in file1.rs to make it work?

seladb
  • 852
  • 1
  • 13
  • 29
  • Possible duplicate of [How to use one module from another module in a Rust cargo project?](https://stackoverflow.com/questions/48071513/how-to-use-one-module-from-another-module-in-a-rust-cargo-project) – Akiner Alkan Jan 21 '19 at 10:30
  • Possible duplicate of [How do you use parent module imports in Rust?](https://stackoverflow.com/questions/20922091/how-do-you-use-parent-module-imports-in-rust) – hellow Jan 21 '19 at 10:33
  • @hellow The answer must be updated. – Boiethios Jan 21 '19 at 10:42
  • Possible duplicate of [What are the valid path roots in the use keyword?](https://stackoverflow.com/questions/54289071/what-are-the-valid-path-roots-in-the-use-keyword) – Boiethios Jan 23 '19 at 13:01

1 Answers1

1

You must use the crate keyword to access to the root of your crate:

use crate::MyStruct;
Boiethios
  • 38,438
  • 19
  • 134
  • 183