mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-15 01:52:42 +00:00
31 lines
622 B
Rust
31 lines
622 B
Rust
// ./src/attribute/cfg.md
|
|
|
|
|
|
// This function only gets compiled if the target OS is linux
|
|
#[cfg(target_os = "linux")]
|
|
fn are_you_on_linux() {
|
|
println!("You are running linux!");
|
|
}
|
|
|
|
// And this function only gets compiled if the target OS is *not* linux
|
|
#[cfg(not(target_os = "linux"))]
|
|
fn are_you_on_linux() {
|
|
println!("You are *not* running linux!");
|
|
}
|
|
|
|
fn part0() {
|
|
are_you_on_linux();
|
|
|
|
println!("Are you sure?");
|
|
if cfg!(target_os = "linux") {
|
|
println!("Yes. It's definitely linux!");
|
|
} else {
|
|
println!("Yes. It's definitely *not* linux!");
|
|
}
|
|
}
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|