Struct mdbook::config::Config

source ·
pub struct Config {
    pub book: BookConfig,
    pub build: BuildConfig,
    pub rust: RustConfig,
    /* private fields */
}
Expand description

The overall configuration object for MDBook, essentially an in-memory representation of book.toml.

Fields§

§book: BookConfig

Metadata about the book.

§build: BuildConfig

Information about the build environment.

§rust: RustConfig

Information about Rust language support.

Implementations§

Load the configuration file from disk.

Updates the Config from the available environment variables.

Variables starting with MDBOOK_ are used for configuration. The key is created by removing the MDBOOK_ prefix and turning the resulting string into kebab-case. Double underscores (__) separate nested keys, while a single underscore (_) is replaced with a dash (-).

For example:

  • MDBOOK_foo -> foo
  • MDBOOK_FOO -> foo
  • MDBOOK_FOO__BAR -> foo.bar
  • MDBOOK_FOO_BAR -> foo-bar
  • MDBOOK_FOO_bar__baz -> foo-bar.baz

So by setting the MDBOOK_BOOK__TITLE environment variable you can override the book’s title without needing to touch your book.toml.

Note: To facilitate setting more complex config items, the value of an environment variable is first parsed as JSON, falling back to a string if the parse fails.

This means, if you so desired, you could override all book metadata when building the book with something like

$ export MDBOOK_BOOK='{"title": "My Awesome Book", "authors": ["Michael-F-Bryan"]}'
$ mdbook build

The latter case may be useful in situations where mdbook is invoked from a script or CI, where it sometimes isn’t possible to update the book.toml before building.

Fetch an arbitrary item from the Config as a toml::Value.

You can use dotted indices to access nested items (e.g. output.html.playground will fetch the “playground” out of the html output table).

Fetch a value from the Config so you can mutate it.

👎Deprecated: use get_deserialized_opt instead

Deprecated, use get_deserialized_opt instead.

Convenience function to fetch a value from the config and deserialize it into some arbitrary type.

Set a config key, clobbering any existing values along the way.

The only way this can fail is if we can’t serialize value into a toml::Value.

Get the table associated with a particular renderer.

Get the table associated with a particular preprocessor.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more

Load a Config from some string.

The associated error which can be returned from parsing.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more