This is my first Rust project and as I have begun to split the code into separate module files, the compiler has started to spit out false warnings of unused code.
Minimal Example:
settings.rs:
pub struct Settings { pub hello: String } pub fn read() -> Settings { Settings { hello: "Hello World!".to_string() } }
client.rs:
#[path = "settings.rs"] mod settings; pub fn print(settings: crate::settings::Settings) { println!("{}", settings.hello); }
main.rs:
mod settings; mod client; fn main() { let settings = settings::read(); client::print(settings); }
cargo run:
warning: struct is never constructed: `Settings` --> hello\src\settings.rs:1:12 | 1 | pub struct Settings { | ^^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: function is never used: `read` --> hello\src\settings.rs:5:8 | 5 | pub fn read() -> Settings { | ^^^^ warning: 2 warnings emitted Finished dev [unoptimized + debuginfo] target(s) in 0.04s Running `...\target\debug\hello.exe` Hello World!
In my real code I'm using the struct from settings in both main and client and am only getting an error for the read function being unused. Why am I getting the unused error(s)? The code is used.
Peter