Created
August 27, 2016 05:15
-
-
Save lifthrasiir/6ba461765630225a9b3b2d85ead33338 to your computer and use it in GitHub Desktop.
Demonstrates the use of conditional attributes for proper documentation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
target | |
Cargo.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "doc-features" | |
version = "0.0.0" | |
authors = [] | |
[lib] | |
path = "lib.rs" | |
[features] | |
default = ["foo"] | |
foo = [] | |
bar = [] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! # Example crate | |
//! | |
//! Demonstrates the use of conditional attributes for proper documentation. | |
//! | |
#![cfg_attr(not(all(feature = "foo", feature = "bar")), | |
doc = " **NOTE: This documentation is *not* complete \ | |
because all feature flags haven't been set while `cargo doc`! \ | |
Try to rebuild the docs with `cargo doc --features \"foo bar\"` instead.**")] | |
//! | |
//! ## Usage | |
//! | |
//! ```toml | |
//! [dependencies] | |
//! doc-features = "0.0.0" | |
//! ``` | |
//! | |
//! You can add [features](#features) like this. | |
//! | |
//! ```toml | |
//! [dependencies] | |
//! doc-features = { version = "0.0.0", features = ["foo", "bar"] } | |
//! ``` | |
//! | |
//! ### Features | |
//! | |
//! These features are enabled by default. | |
//! You can disable them via `default-features = false` option to the dependency. | |
//! | |
//! * `foo`: Enables foo. | |
//! | |
//! These features are optional. | |
//! | |
//! * `bar`: Enables bar. | |
/// Prints foo. | |
/// | |
/// [Cargo feature `foo` is required for this function.](./index.html#features) | |
#[cfg(feature = "foo")] | |
pub fn print_foo() { | |
println!("foo"); | |
} | |
/// Prints bar. | |
/// | |
/// [Cargo feature `bar` is required for this function.](./index.html#features) | |
#[cfg(feature = "bar")] | |
pub fn print_bar() { | |
println!("bar"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment