I didn't know that. Thanks. Well, the original code (and error) was
error[E0432]: unresolved import `jonathan`
--> src/bin/gui.rs:31:5
|
31 | use jonathan::read_csv;
| ^^^^^^^^ use of unresolved module or unlinked crate `jonathan`
|
= help: if you wanted to use a crate named `jonathan`, use `cargo add jonathan` to add it to your `Cargo.toml`
but Cargo.toml includes
[package]
name = "jonathan"
...
Well, is there a best practice for things like that? I just want to use read_csv.
If it is present (empty or not), you should not get the error "unresolved import jonathan" unless something else is wrong. What are the full contents of your Cargo.toml file?
Thanks kpreid. Well, I had deleted the src/lib.rs. I succeed the build now. Here is what I did.
I tried to add in src/lib.rs
mod read_csv;
mod types;
but I got
error[E0603]: module `read_csv` is private
--> src/bin/gui.rs:31:15
|
31 | use jonathan::read_csv;
| ^^^^^^^^ private module
|
note: the module `read_csv` is defined here
--> path/to/src/lib.rs:1:1
|
1 | mod read_csv;
| ^^^^^^^^^^^^
I changed mod read_csv in src/lib.rs to
pub mod read_csv;
and build succeeded.
Well, is there a good reference for understanding the system of binary and library crates?
in this example, there are at least 3 different crates in the same package:
a binary crate gui, root module is source file src/bin/gui.rs
a binary crate jonathan (same as the package name), root module is src/main.rs
a library crate jonathan (same as the package name), root module is src/lib.rs
when you use crate::read_csv in each crate, the crate keyword refers to the root module of its own crate, so it will only work in main.rs where you have declared the module with mod read_csv;
when you write jonathan::read_csv, jonathan refers to the library crate. this can be resolved correctly if you have pub mod read_cvs; in lib.rs. it will NOT work with an empty lib.rs
Thank you nerditation. I didn't expect there was also the gui binary crate. At first I was confused by the word "root module". I was thinking like "Isn't modules' root a directory?". Actually there are several roots!
Your link is also a great reading. I don't think I can understand everything you wrote right now, but I think I can learn from your writing while working on a project. Thank you.