Yesterday I tried to write a simple program in Rust that links to X11. So I googled for a library and found x11-rs. This library also comes with a couple examples. I chose the hello-world.rs.
Because I plan to write a real application I already had a very basic directory structure
No error. But why? Why is cargo not linking correctly? I read the cargo docs up and down and ended up with a build.rs file and a modified Cargo.toml.
Then an idea came to mind. Is it possible that the library takes precedence if present? I moved all the code to mod.rs and just called the function from main.rs. The result was a XWindow popping up. Wow! To prove the assumption I removed the files lib.rs and mod.rs entirely and moved all program logic back to main.rs.
Everything else remained unchanged. I am not sure about the why. I didn’t read that anywhere, but probably this behaviour is documented somewhere. I guess the philosophy Rust tries to enforce here is that if we have a library, it should be the place to put all the main program logic (it’s a library right?). The main shall be reduced to a bare minimum just calling into the library and other crates and Rust doesn’t link against it.