Skip to content

Commit ffba331

Browse files
committed
Include doc example only if "json" is enabled
Signed-off-by: Matthias Beyer <[email protected]>
1 parent 3842ecb commit ffba331

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

src/builder.rs

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,44 +34,46 @@ use crate::{config::Config, path::Expression, source::Source, value::Value};
3434
///
3535
/// # Examples
3636
///
37-
/// ```rust
38-
/// # use config::*;
39-
/// # use std::error::Error;
40-
/// # fn main() -> Result<(), Box<dyn Error>> {
41-
/// let mut builder = Config::builder()
42-
/// .set_default("default", "1")?
43-
/// .add_source(File::new("config/settings", FileFormat::Json))
44-
/// // .add_async_source(...)
45-
/// .set_override("override", "1")?;
46-
///
47-
/// match builder.build() {
48-
/// Ok(config) => {
49-
/// // use your config
50-
/// },
51-
/// Err(e) => {
52-
/// // something went wrong
53-
/// }
54-
/// }
55-
/// # Ok(())
56-
/// # }
57-
/// ```
58-
///
59-
/// If any [`AsyncSource`] is used, the builder will transition to [`AsyncState`].
60-
/// In such case, it is required to _await_ calls to [`build`](Self::build) and its non-consuming sibling.
61-
///
62-
/// Calls can be not chained as well
63-
/// ```rust
64-
/// # use std::error::Error;
65-
/// # use config::*;
66-
/// # fn main() -> Result<(), Box<dyn Error>> {
67-
/// let mut builder = Config::builder();
68-
/// builder = builder.set_default("default", "1")?;
69-
/// builder = builder.add_source(File::new("config/settings", FileFormat::Json));
70-
/// builder = builder.add_source(File::new("config/settings.prod", FileFormat::Json));
71-
/// builder = builder.set_override("override", "1")?;
72-
/// # Ok(())
73-
/// # }
74-
/// ```
37+
#[cfg_attr(feature = "feature", doc = r##"
38+
```rust
39+
# use config::*;
40+
# use std::error::Error;
41+
# fn main() -> Result<(), Box<dyn Error>> {
42+
let mut builder = Config::builder()
43+
.set_default("default", "1")?
44+
.add_source(File::new("config/settings", FileFormat::Json))
45+
// .add_async_source(...)
46+
.set_override("override", "1")?;
47+
48+
match builder.build() {
49+
Ok(config) => {
50+
// use your config
51+
},
52+
Err(e) => {
53+
// something went wrong
54+
}
55+
}
56+
# Ok(())
57+
# }
58+
```
59+
60+
If any [`AsyncSource`] is used, the builder will transition to [`AsyncState`].
61+
In such case, it is required to _await_ calls to [`build`](Self::build) and its non-consuming sibling.
62+
63+
Calls can be not chained as well
64+
```rust
65+
# use std::error::Error;
66+
# use config::*;
67+
# fn main() -> Result<(), Box<dyn Error>> {
68+
let mut builder = Config::builder();
69+
builder = builder.set_default("default", "1")?;
70+
builder = builder.add_source(File::new("config/settings", FileFormat::Json));
71+
builder = builder.add_source(File::new("config/settings.prod", FileFormat::Json));
72+
builder = builder.set_override("override", "1")?;
73+
# Ok(())
74+
# }
75+
```
76+
"##)]
7577
///
7678
/// Calling [`Config::builder`](Config::builder) yields builder in the default state.
7779
/// If having an asynchronous state as the initial state is desired, _turbofish_ notation needs to be used.

0 commit comments

Comments
 (0)