Add the license field to your Cargo.toml file using a standard SPDX identifier like MIT OR Apache-2.0 to allow others to use your crate.
Add a license field to the [package] section of your Cargo.toml file using a valid SPDX identifier. For open-source crates, MIT OR Apache-2.0 is the standard choice used by the Rust project itself.
[package]
name = "my_crate"
version = "0.1.0"
edition = "2024"
license = "MIT OR Apache-2.0"
If you are not publishing to crates.io, you can omit this field, but it is required for public releases.
A license is a legal agreement that tells others how they can use, modify, and share your code. Without one, people cannot legally use your crate, which stops them from helping you or building on your work. Think of it like a sign on your house that says whether visitors are allowed to enter or if they need permission first.