#[non_exhaustive]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 (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.book: BookConfigMetadata about the book.
build: BuildConfigInformation about the build environment.
rust: RustConfigInformation about Rust language support.
Implementations§
Source§impl Config
impl Config
Sourcepub fn from_disk<P>(config_file: P) -> Result<Config, Error>
pub fn from_disk<P>(config_file: P) -> Result<Config, Error>
Load the configuration file from disk.
Sourcepub fn update_from_env(&mut self) -> Result<(), Error>
pub fn update_from_env(&mut self) -> Result<(), Error>
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_book->bookMDBOOK_BOOK->bookMDBOOK_BOOK__TITLE->book.titleMDBOOK_BOOK__TEXT_DIRECTION->book.text-direction
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.
Sourcepub fn get<'de, T>(&self, name: &str) -> Result<Option<T>, Error>where
T: Deserialize<'de>,
pub fn get<'de, T>(&self, name: &str) -> Result<Option<T>, Error>where
T: Deserialize<'de>,
Get a value from the configuration.
This fetches a value from the book configuration. The key can have
dotted indices to access nested items (e.g. output.html.playground
will fetch the “playground” out of the html output table).
This can only access the output and preprocessor tables.
Returns Ok(None) if the field is not set.
Returns Err if it fails to deserialize.
Sourcepub fn contains_key(&self, name: &str) -> bool
pub fn contains_key(&self, name: &str) -> bool
Returns whether the config contains the given dotted key name.
The key can have dotted indices to access nested items (e.g.
preprocessor.foo.bar will check if that key is set in the config).
This can only access the output and preprocessor tables.
Sourcepub fn preprocessors<'de, T>(&self) -> Result<BTreeMap<String, T>, Error>where
T: Deserialize<'de>,
pub fn preprocessors<'de, T>(&self) -> Result<BTreeMap<String, T>, Error>where
T: Deserialize<'de>,
Returns the configuration for all preprocessors.
Sourcepub fn outputs<'de, T>(&self) -> Result<BTreeMap<String, T>, Error>where
T: Deserialize<'de>,
pub fn outputs<'de, T>(&self) -> Result<BTreeMap<String, T>, Error>where
T: Deserialize<'de>,
Returns the configuration for all renderers.
Sourcepub fn set<S, I>(&mut self, index: I, value: S) -> Result<(), Error>
pub fn set<S, I>(&mut self, index: I, value: S) -> Result<(), Error>
Set a config key, clobbering any existing values along the way.
The key can have dotted indices for nested items (e.g.
output.html.playground will set the “playground” in the html output
table).
§Errors
This will fail if:
- The value cannot be represented as TOML.
- The value is not a correct type.
- The key is an unknown configuration option.