Can't the files of two folders in src directory reference each other

This is my directory structure

       |    |
       |    |
       |    |
       |    |

I want to quote file and struct in file

use crate::common::response;
use crate::domain::user;

use actix_web :: {

error message:

error[E0432]: unresolved import `crate::common`
 --> web/covid_19/src/api/
1 | use crate::common::response;
  |            ^^^^^^ could not find `common` in the crate root

error[E0432]: unresolved import `crate::domain`
 --> web/covid_19/src/api/
2 | use crate::domain::user;
  |            ^^^^^^ could not find `domain` in the crate root

Is there any solution? It seems that rust does not support this?

Of course Rust supports this. Do you not have a or file? Can you show us your mod statements?

hahah, I just solved it. I'm in add

mod domain;
mod common;

But I'm very curious about why adding in file doesn't take effect, but adding in file takes effect and I have both file

The and files define two separate crates. You can access the crate from the crate with whatever package name you have specified in your Cargo.toml instead of crate::. Other files are in the crate that mentions them with a mod statement. (Don't mention it with a mod statement in both — that will result in the file being compiled twice.)

In other words, if you add crates in, don't add them in file, right?

modules, but yes

Thank you for your prompt reply :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.