11.3.1 Custom
target_os 같은 몇 가지 조건은 암시적으로 rustc에 제공되지만, 사용자 정의 조건들은 반드시 --cfg 플래그를 사용해서 rustc에게 전달되어야 한다.
// custom.rs
#[cfg(some_condition)]
fn conditional_function() {
println!("condition met!")
}
fn main() {
conditional_function();
}
사용자 정의 cfg 플래그 없이:
$ rustc custom.rs && ./custom
No such file or directory (os error 2)
사용자 정의 cfg 플래그와 함께:
$ rustc --cfg some_condition custom.rs && ./custom
condition met!