Run cargo new --lib to create a Rust library crate with a src/lib.rs file for reusable code.
Create a library crate by running cargo new --lib followed by your crate name, which generates a project with a src/lib.rs file instead of src/main.rs.
cargo new --lib my_library
This command sets up the directory structure and Cargo.toml configured for a library, allowing you to define public modules and functions in src/lib.rs for other crates to use.
A library crate is a package of reusable code that other programs can import, rather than a standalone program you run directly. Think of it like a toolbox of functions you build once and share with others, instead of building a specific machine. You use this when you want to create shared logic, like a math calculator or a data parser, that multiple projects can depend on.