How to Create Different Build Profiles (Dev, Staging, Production) in Rust

Create custom build profiles in Cargo.toml to manage optimization and debug settings for dev, staging, and production environments.

Define custom profiles in Cargo.toml under [profile.*] sections to control build settings for different environments. Add [profile.dev], [profile.staging], and [profile.prod] blocks with your specific optimization and debug settings, then build using cargo build --profile <name>.

[profile.dev]
opt-level = 0
debug = true

[profile.staging]
opt-level = 2
debug = true

[profile.prod]
opt-level = 3
debug = false
lto = true
cargo build --profile staging
cargo build --profile prod