āÆ cargo check
Checking nzb-parser v0.1.0 (redacted)
error[E0432]: unresolved imports `nzb_parser::File`, `nzb_parser::Meta`, `nzb_parser::Segment`
--> src\parser.rs:2:18
|
2 | use nzb_parser::{File, Meta, Segment};
| ^^^^ ^^^^ ^^^^^^^ no `Segment` in the root
| | |
| | no `Meta` in the root
| no `File` in the root
|
= help: consider importing this struct instead:
std::fs::File
error[E0432]: unresolved import `nzb_parser::NZB`
--> src/main.rs:4:5
|
4 | use nzb_parser::NZB;
| ^^^^^^^^^^^^^^^ no `NZB` in the root
For more information about this error, try `rustc --explain E0432`.
error: could not compile `nzb-parser` (bin "nzb-parser") due to 2 previous errors
Cargo run however successfully executes and prints the "unresolved" struct:
error[E0432]: unresolved imports `crate::File`, `crate::Meta`, `crate::Segment`
--> src\parser.rs:2:13
|
2 | use crate::{File, Meta, Segment};
| ^^^^ ^^^^ ^^^^^^^ no `Segment` in the root
| | |
| | no `Meta` in the root
| no `File` in the root
|
= help: consider importing one of these structs instead:
std::fs::File
nzb_parser::File
= help: consider importing this struct instead:
nzb_parser::Meta
= help: consider importing this struct instead:
nzb_parser::Segment
error[E0432]: unresolved import `crate::NZB`
--> src/main.rs:4:5
|
4 | use crate::NZB;
| ^^^^^^^^^^ no `NZB` in the root
|
help: consider importing this struct instead
|
4 | use nzb_parser::NZB;
| ~~~~~~~~~~~~~~~
For more information about this error, try `rustc --explain E0432`.
error: could not compile `nzb-parser` (bin "nzb-parser") due to 2 previous errors
Do you have a mod parser; in your main.rs maybe? If you have a library crate and binary crates within the same package, you should only define modules in your library (lib.rs) and not in your binaries (like main.rs). Inside of your library and its submodules you can import types from other modules in the library with use crate:: and in your main.rs you can import public items from your library with use nzb_parser::.
That was it. I had mod parser; and mod utils; in both lib.rs and main.rs. But how do I access private functions in main.rs?
error[E0432]: unresolved import `parser`
--> src/main.rs:2:5
|
2 | use parser::{parse_files, parse_metadata};
| ^^^^^^ use of undeclared crate or module `parser`
error[E0432]: unresolved import `utils`
--> src/main.rs:4:5
|
4 | use utils::read_xml_file;
| ^^^^^ use of undeclared crate or module `utils`
For more information about this error, try `rustc --explain E0432`.
error: could not compile `nzb-parser` (bin "nzb-parser") due to 2 previous errors
parse_files, parse_metadata, and read_xml_file are all using pub(crate) fn ...
Your binary is not the same crate as your library, they are distinct crates (within the same package). Therefore your binary can only access the public interface of your library. I'd just make all items your binary needs access to public.