# Doctests that require a non-default feature, is it possible?

**URL:** <https://users.rust-lang.org/t/doctests-that-require-a-non-default-feature-is-it-possible/29529>\
**Category:** uncategorized\
**Created:** [June 22, 2019, 2:05pm UTC](https://users.rust-lang.org/t/doctests-that-require-a-non-default-feature-is-it-possible/29529 "2019-06-22T14:05:10Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![ExpHP](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/exphp/32/13145_2.png) [@ExpHP](https://users.rust-lang.org/u/ExpHP)\
**Post date:** [June 22, 2019, 8:32pm UTC](https://users.rust-lang.org/t/doctests-that-require-a-non-default-feature-is-it-possible/29529/4 "2019-06-22T20:32:31Z")

</div>

To take care of things like this you can manually use the `doc` attribute instead of relying on the `///` sugar.

E.g.

````rust
/// Documentation relevant to all users.
/// Documentation relevant to all users.
/// Documentation relevant to all users.
///
/// Paragraph that mentions the feature.
#[cfg_attr(feature = "feature", doc = r##"
Paragraph that only appears when feature is enabled.

```
// doctest that only exists when the feature is enabled
```
"##)]

````

This technique [was used in frunk](https://github.com/lloydmeta/frunk/blob/7fa5f4766bca823ee4def45b4881cabdc285520b/src/lib.rs#L15) for similar purposes.

P.S. in case it isn't enabled in your `default-features`, don't forget to enable the feature in [`[package.metadata.docs.rs]`](https://docs.rs/about) to make sure it appears in online documentation!

---

_[View the full topic](https://users.rust-lang.org/t/doctests-that-require-a-non-default-feature-is-it-possible/29529)._
