What lib.rs do with main.rs? Because I see most project use this only lib.rs but without main.rs file. Why?

what can lib.rs do with main.rs file?
why most project don't include main.rs instead with lib.rs?

main.rs defines a binary crate, lib.rs defines a library crate;see project layout in the cargo doc

if a crate defines both a binary and a library, the code in main.rs can make use of the library defined in the same crate (this is sometimes used to define multiple tools in a crate, sharing code), but not vice versa

lib.rs is for a library crate that other crates can use as dependencies.

main.rs is for an executable crate that is the final product.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.