Env Consts Reveal The Target Platform
Read OS, ARCH, FAMILY, and linker suffixes from env::consts so install paths and binary names follow the target platform.
Code
use std::env::consts::{ARCH, DLL_SUFFIX, EXE_SUFFIX, FAMILY, OS};
fn main() {
// compile-time constants: the toolchain bakes in the target platform
println!("os: {OS}");
println!("arch: {ARCH}");
println!("family: {FAMILY}");
// suffixes decide binary names: main vs main.exe, libfoo vs foo.dll
println!("exe suffix: '{EXE_SUFFIX}'");
println!("dll suffix: '{DLL_SUFFIX}'");
// runtime branch keyed on the platform family
let separator = if FAMILY == "windows" { '\\' } else { '/' };
println!("path separator: {separator}");
}How the snippet works
Env Consts Reveal The Target Platform is built around the function main.
Applying it
The demo output is labeled (os:, arch:, family:); each label names the call that printed it.
Statements that matter
let separator = if FAMILY == "windows" { '\\' } else { '/' };
Interactive Tools for This Topic
Dotenv File ParserParse .env file content into a JSON object, handling comments, export prefixes, single quotes, and double-quoted escape sequences.Git Conventional Commit BuilderBuild and validate Conventional Commits v1.0.0 messages with type, scope, breaking markers, 72-char subject counter, body, footers, and git CLI command.Glob Pattern TesterCompile glob patterns with *, **, ?, character classes, and braces into regex and test them against a list of candidate file paths.Tar Archive Command BuilderBuild safe tar create, extract, and list commands for gzip, xz, zstd, and bzip2 archives with excludes, target directory (-C), and flag explanations.
FAQ
- What does Env Consts Reveal The Target Platform print when run?
- Running the file directly is enough — expect labeled output lines such as `os:`, `arch:`, `family:`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.