I'm trying to call a function belonging to some module from another module (for code factoring, organization, etc).
Here is my crate structure:
➜ mod_test git:(master) ✗ tree
.
├── Cargo.lock
├── Cargo.toml
└── src
├── bin
│ └── one.rs
├── lib
│ └── two.rs
└── main.rs
3 directories, 5 files
In main I declare:
pub mod bin {
pub mod one;
}
pub mod lib {
pub mod two;
}
and all these files simply contain a trivial pub fn main() {println!("hello");}.
At this point, everything is okay.
Now, is it possible to call lib::two::main from bin/one.rs?
None of use crate::lib::two;, use super::lib::two;, use self::super::lib::two; added in bin/one.rs work.
edit: I have:
rustc 1.42.0 (b8cedc004 2020-03-09)installed on Linux 5.3.0-45-generic, for what it's worth.edit 2: whenever using the
superkeyword, I get this mysterious error fromrustc:
error[E0433]: failed to resolve: there are too many leading `super` keywords
and I can't find any troubleshooting about this anywhere.
edit 3: adding a
lib.rsfile insrcdeclaring thelibmodule structure, and writinguse mod_test::lib::two;inone.rsworks, but:1) it defeats the idea of not multiplying "dumb module declaration files" in my crate.
2) I have to literally copy the exact same information at two different places (in
main.rsand inlib.rs)3)
use mod_test::lib::two;is the only working syntax, usingcrateorsuperkeywords still result in arcane compiler errors