Hello,
I am experimenting with library creation, and I am having some odd problems.
I have my library in one folder, and my binary in the other.
Here is the directory structure:
I am trying to use this new library in my main function, but I am getting this error:
error[E0432]: unresolved import `test_library::it_works`
--> src\main.rs:2:5
|
2 | use test_library::it_works;
| ^^^^^^^^^^^^^^^^^^^^^^ no `it_works` in the root
error: aborting due to previous error
For more information about this error, try `rustc --explain E0432`.
error: could not compile `library_test`.
To learn more, run the command again with --verbose.
Here is the main.rs file:
extern crate test_library;
use test_library::it_works;
fn main() {
println!("Hello, world!");
it_works();
}
However, taking a look at my lib.rs file, this function is in fact in there (the root), it's just:
pub fn it_works() {
assert_eq!(2 + 2, 4);
println!("It works!");
}
I did add the test_library to my cargo.toml file under the bins dependencies:
[dependencies]
test_library = "0.1.0"
I'm not getting it, can someone tell me what I missed?
I am having a similar problem in the library when I add in my prelude file into the lib.rs file like this:
pub mod prelude;
pub fn it_works() {
assert_eq!(2 + 2, 4);
println!("It works!");
}
I get about the same error, but for the prelude file:
error[E0432]: unresolved import `super::astruct`
--> src\prelude.rs:1:16
|
1 | pub use crate::astruct::ThatThing;
| ^^^^^^^ maybe a missing crate `astruct`?
error: aborting due to previous error
For more information about this error, try `rustc --explain E0432`.
error: could not compile `test_library`.
To learn more, run the command again with --verbose.
Here is my prelude.rs file, which is in the same src folder as lib.rs:
pub use crate::astruct::ThatThing;
And here is the other file, called astruct.rs which is also in the same src folder as lib.rs:
pub struct ThatThing {
pub anum : i64
}
Please let me know what I need to fix; I'm new to libraries, and I can't find a good explanation.
I did read the help that rustc gives, but it didn't really clarify the solution.
Thanks!