Struct in module, used in another module : E0308

I am trying to learn Rust but it is fighting me every step of the way. I have the following code (in a module called

let search : softtube::Search = match text.len() {
                0 => softtube::Search::Limit(-1),
                _ => softtube::Search::Text(text)
            };;  <-- Error occurs here!!

Search is defined in a module called

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Search {

And now I am getting the error :

let search : softtube::Search = match text.len() { ... }
mismatched types

expected enum `softtube::Search`, found enum `events::softtube::Search`

note: expected type `softtube::Search`
found type `events::softtube::Search`rustc(E0308)

So it says on the second row of the error message that search is of the type softtube::Search, but later, on the last row it says it is the type events::softtube::Search!?! Why Rust? Why are you punishing me?

The first couple of weeks I wrote all Rust code in just to avoid crap like this, but now I have to bite the bullet and finally learn how to do this. So can anyone help me with this? Please?

Do you have Search defined multiple times in different modules?

No, but I do have a couple of lower case functions and variables named 'search', can that cause this problem?

Like @KrishnaSannasi, I can just guess. It's better if you can provide minimal code that can compile that produce the same error. When trying to reproduce with a minimal code, I tend to find the problem myself. This may help some how?

1 Like

@limira, I will try that, but in my case they are actually different files. Doesn't that matter?

I link them in with this syntax (for some reason I don't need the #[path="path"] in

mod softtube;

No, you just do this:

// in
mod mod1; // and a file `./` or `./mod1/`
mod mod2;
mod mod3;

If I don't use the path-syntax (in files other than, I get this error:

file not found for module `misc`
help: name the file either events/ or events/misc/ inside the directory "src"rustc(E0583)

But good news, my problem seemed to be the missing 'crate::' in front of softtube::Search() that you used in the playground example! Thanks for that!

I can't figure out how to make the playground link, but I just needed to add the crate::...

I think you place your files in wrong folders/directories. If they are all in their correct directories, you don't have to #[path=""] (In fact, this the first time I see it).

If you want to avoid the crate::, bring it into scope by using use ...;

use some::path::to::EnumItem;
let item = EnumItem::Variant;

Well, I created a project with 'cargo new' and then place all my files inside the src folder, isn't that correct?

So basically


  • ....


If every mod are in

mod mod1;

You have two options for the file (that contains code for your mod1):

// or 

But if you want a mod2 in module mod1:

// in (or mod1/
mod mod2;

You have to place the file in:

src/mod1/ //(The file is in folder: src/mod1)
// or

I am confident that I have completely misunderstood a whole lot of things, but anyway here are my code simplified a lot :

  1. Go to and comment out '#[path=""]' and you will get the module error I talked about.
file not found for module `misc`
help: name the file either events/ or events/misc/ inside the directory "src"rustc(E0583)
  1. Go to and remove the three 'crate::' and you will get the error message I originally asked about. But it works with the 'crate::' so I am happy with that for now, but just in case you wanted to see exactly how I have messed this up :slight_smile:

About my use of the 'mod' keyword in and, I have a suspicion that I am using that very wrong. The only thing I am trying to achieve here at this moment is to not have all the code in one file ( I am not trying to build a "library" (cargo new --lib) or anything...

A few YouTube-videos later and I realized that you can write :

use crate::module;


use super::module;

That makes things easier... :slight_smile:

I prefer to learn things by doing, until I go completely mad, and then I do what I should have done from the beginning. Read the manual, and learn from others...

Thanks everybody who helped me...

Yeah, I understand that. But I think read The Book first is a good idea. It helps me very much.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.