In the Importing External Crates section of the Rust book the author creates main.rs
file in an already existing library project. I randomly picked up a bunch of crates from crates.io, examined their structure and did not find any project containing both lib.rs
and main.rs
files. So i'm wondering if it is common to have both files in a library project hosted at crates.io
or it should be considered a poor style?
To be more clear, I'm asking about developing a library designed to share with the community, not about an executable with a few days lifecycle.
I'm aware of Cargo's testing capabilities, so the purpose of main.rs
I want to add to the library is not testing. A good example of how my main.rs
in the library crate should relate to the library is how curl
command line tool is related to libcurl
library. To my mind it is convenient to have a project for which cargo build
builds an executable by default but all the functionality is available for importing as a library.
src/main.rs
along withsrc/lib.rs
instead ofsrc/bin/curl.rs
? – Sergey Jul 31 '15 at 06:50