Cannot import Color from Vectors file

So I have three files-,,
In I define a Vector struct and a Color alias for it.
In I have a function that takes a Color as argument and prints something out.
Now the import in the just doesn't work.
At the top of the file I have this:

mod vectors;
use vectors::Color;

and at the top of (that doesn't give an error though):

mod vectors;
mod colors;
use vectors::Color;
use colors::*;

the compiler tells me to do this: dpaste/K8V7 (Python)
but that's not how i want my folders to look like.

You need only one mod name; for each module.

what do you mean?
I have 3 files, each one importing something different.
Also I don't see how that solves the import errors.

The colors file should be:

use crate::vectors::Color;

The main file:

mod vectors;
mod colors;
use crate::vectors::Color;
use crate::colors::*;

The crate:: is optional only in the same file as the mod statement. You should only ever mention each file once with a mod statement.

According to how you've written it, you actually have four modules:

  • A main module in
  • A vectors module, declared in and with its contents in
  • A colors module, declared in main.rd and with its contents in
  • A colors::vectors module, declared in and would have its contents in colors/ (although that file presumably doesn't exist)

I think the use statement in is interpreted relative to the current module, so it refers to colors::vectors::Color, which doesn't exist. You probably don't want the colors:: vectors module, so you can remove the mod statement in, which declares it. You should also disambiguate the use in to be relative to the crate root to ensure you are referencing the right thing:

use crate::vectors::Color;
1 Like

fixed. thank you

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.