Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

사용자 정의

target_os와 같은 일부 조건은 rustc에 의해 암시적으로 제공되지만, 사용자 정의 조건은 --cfg 플래그를 사용하여 rustc에 전달되어야 합니다.

#[cfg(some_condition)]
fn conditional_function() {
    println!("조건 충족!");
}

fn main() {
    conditional_function();
}

사용자 정의 cfg 플래그 없이 실행하면 어떻게 되는지 확인해 보세요.

사용자 정의 cfg 플래그 사용 시:

$ rustc --cfg some_condition custom.rs && ./custom
condition met!