Profiles and compiler options
Quick answer
A Cargo profile chooses compiler settings for a build, such as optimization and debug information. Use the development profile for iteration and measure release builds for realistic performance.
Build settings are not language rules
cargo build normally uses dev; cargo build --release uses release. Overflow checking, debug assertions, debug information and panic strategy are configurable. Do not rely on a profile to define application arithmetic. Use checked or wrapping arithmetic explicitly when required.
fn main() { println!("{:?}", 255u8.checked_add(1)); println!("{}", 255u8.wrapping_add(1)); }Expected stdout (not executed):
None0The two operations keep these semantics in either profile.
Manual terminal step; not executed. Expected behavior (environment dependent):
Two builds using different profiles.Run in a reviewed local package; compare artifacts without assuming a speedup.
Common mistake
A release profile is not a guarantee of correct or fast code.
Try it yourself
Find the profile configuration for debug information and describe why it can help diagnose release failures.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Profiles and compiler options — practice quiz
Choose one answer per question. Code examples are predictions; review explanations after attempting them.
Overflow must return an error in both dev and release. Which approach is appropriate?
Profiles and compiler options — example 1. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```rust fn main() { println!("{:?}", 255u8.checked_add(1)); println!("{}", 255u8.wrapping_add(1)); } ``` What standard output should the program produce if its run succeeds? Ignore Cargo and diagnostic messages.
Profiles and compiler options — example 2. Read the code; do not execute it for this question. Assume the lesson’s stated setup, compatible dependencies and toolchain, and a fresh disposable directory for file-creating examples. ```bash cargo build --offline cargo build --release --offline ``` Which outcome or interpretation best matches this example?