I am trying to write a crate called bar
, the structure looks like this
src/
├── bar.rs
└── lib.rs
My src/lib.rs
looks
The important part you are missing is that crates define their own module. That is, your crate bar
implicitly defines a module called bar
, but you also have created a module called bar
inside that. Your struct resides within this nested module.
If you change your main to use bar::bar::baz;
you can progress past this. You will have to decide if that's the structure you want though. Most idiomatic Rust projects would not have the extra mod
and would flatten it out:
src/lib.rs
pub struct Baz {
// stuff
}
impl Baz {
// stuff
}
Unfortunately, your example code cannot compile, as you have invalid struct definitions, and you call methods that don't exist (new
), so I can't tell you what else it will take to compile.
Also, structs should be PascalCase
.