expression

Use the target executable suffix

Executable suffixes vary by target. Use EXE_SUFFIX for a name intended for the current compiled target, and use an explicit target manifest for artifacts built for other targets. The example verifies the current name and prints a stable confirmation. Fixture: Expected stdout (not executed): executable name ready Expected stderr: (empty) Expected exit: 0 Common mistake: Hard-coding .exe on every OS or using the build host suffix for a cross-target release.

Formal Syntax & Structure

rust syntaxrust
format!("tool{}", std::env::consts::EXE_SUFFIX)

Working Example

Example Snippetrust
fn main() {    let name = format!("inventory{}", std::env::consts::EXE_SUFFIX);    assert!(name.starts_with("inventory"));    assert_eq!(&name["inventory".len()..], std::env::consts::EXE_SUFFIX);    println!("executable name ready");}
Rust Reference