Skip to content

Instantly share code, notes, and snippets.

@lifthrasiir
Created August 27, 2016 05:15
Show Gist options
  • Save lifthrasiir/6ba461765630225a9b3b2d85ead33338 to your computer and use it in GitHub Desktop.
Save lifthrasiir/6ba461765630225a9b3b2d85ead33338 to your computer and use it in GitHub Desktop.
Demonstrates the use of conditional attributes for proper documentation
target
Cargo.lock
[package]
name = "doc-features"
version = "0.0.0"
authors = []
[lib]
path = "lib.rs"
[features]
default = ["foo"]
foo = []
bar = []
//! # 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