3

I encountered this error when I try to use use crate::some_module but I can use use my_package::some_module. Anyone know why it works with the latter, but doesn't work with the first one?

Error:

error[E0432]: unresolved import `crate::some_module`

unresolved import
   help: a similar path exists: `my_package::some_module`

Cargo.toml

[package]
name = "my_package"
//Bunch of other lines and dependencies

lib.rs

pub mod some_module;
//Bunch of other modules

Project structure:

my_package
|_src
  |_main.rs
  |_lib.rs
  |_some_module.rs

|_Cargo.toml
Yosi Pramajaya
  • 3,895
  • 2
  • 12
  • 34
  • Upload the project to github if you can. – Michał Hanusek Feb 29 '20 at 21:22
  • I can't. But also, I don't think that's necessary... Do you have any idea why I can use direct package name but not `crate`? – Yosi Pramajaya Mar 01 '20 at 04:12
  • 3
    Relevant answer: https://stackoverflow.com/a/57773297 The library (entry point `lib.rs`) and binary (entry point `main.rs`) are actually different crates. So `my_package` is an external library in `main.rs`, and can not be referred to as `crate::`. – goto-bus-stop Mar 01 '20 at 15:53
  • 2
    Does this answer your question? [Rust modules confusion when there is main.rs and lib.rs](https://stackoverflow.com/questions/57756927/rust-modules-confusion-when-there-is-main-rs-and-lib-rs) – goto-bus-stop Mar 01 '20 at 15:55
  • Yes. Thank you! Rust modules concept is pretty unique, so I need to get use to it first, I guess. – Yosi Pramajaya Mar 03 '20 at 00:42

0 Answers0