Importing a file

I am new in rustlang and I am struggling to import.

I have 3 .rs file in my project.

  1. main.rs
  2. animal.rs
  3. kind.rs

There is no error in the following situation:
In main.rs: There is no import
In animal.rs : mod kind;
In kind.rs: There is a structre named Kind

,but there is a problem in the following situation:
In main.rs: mod animal;
In animal.rs : mod kind;
In kind.rs: There is a structre named Kind

Error no: E0583. Compiler says that "unresolved module".

What is the problem?

You should do it like this:

// main.rs
mod animal;
mod kind;
use crate::animal::Cat;
// animal.rs
use crate::kind::Kind;

struct Dog {}
struct Cat {}
// kind.rs
use crate::animal::Dog;
struct Kind {}

Thank you very much.

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.