自定义 - Rust By Example
Description: Rust by Example (RBE) is a collection of runnable examples that illustrate various Rust concepts and standard libraries.

## 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!