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

Custom

Деякі умовні параметри, як-от target_os, неявно надаються rustc, але користувацькі умовні параметри мають передаватися до rustc за допомогою прапорця --cfg.

#[cfg(some_condition)]
fn conditional_function() {
    println!("condition met!");
}

fn main() {
    conditional_function();
}

Спробуйте запустити це, щоб побачити, що станеться без користувацького прапорця cfg.

З користувацьким прапорцем cfg:

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