File not found for module "xxx"

I get this error in vscode , why?

and how to fix it?

Since engin.rs is in src/ you have to declare it in lib.rs.
Then you can use it in browser.rs with:

use crate::engin;
1 Like

Or alternatively move browser.rs into its own directory and put engin.rs in there with it:

src/
    lib.rs
    browser/
            mod.rs <-- renamed from browser.rs
            engin.rs
2 Likes

Worth noting that another valid strategy is to just add a subdirectory, and not rename browser.rs

src/
    lib.rs
    browser.rs
    browser/
            engin.rs

This is equivalent to @OptimisticPeach's layout, just a different style. engin is still a sub module of browser here.

1 Like

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