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!("condition met!");
}

fn main() {
    conditional_function();
}

カスタム cfg フラグなしで何が起こるか確認するために、これを実行してみてください。

カスタム cfg フラグを指定した場合:

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