How to Create a Library Crate in Rust

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.