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§

source§

impl Config

source

pub fn from_disk<P: AsRef<Path>>(config_file: P) -> Result<Config>

Load the configuration file from disk.

source

pub fn update_from_env(&mut self)

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.

source

pub fn get(&self, key: &str) -> Option<&Value>

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).

source

pub fn get_mut(&mut self, key: &str) -> Option<&mut Value>

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

source

pub fn get_deserialized<'de, T: Deserialize<'de>, S: AsRef<str>>( &self, name: S ) -> Result<T>

👎Deprecated: use get_deserialized_opt instead

Deprecated, use get_deserialized_opt instead.

source

pub fn get_deserialized_opt<'de, T: Deserialize<'de>, S: AsRef<str>>( &self, name: S ) -> Result<Option<T>>

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

source

pub fn set<S: Serialize, I: AsRef<str>>( &mut self, index: I, value: S ) -> Result<()>

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.

source

pub fn get_renderer<I: AsRef<str>>(&self, index: I) -> Option<&Table>

Get the table associated with a particular renderer.

source

pub fn get_preprocessor<I: AsRef<str>>(&self, index: I) -> Option<&Table>

Get the table associated with a particular preprocessor.

Trait Implementations§

source§

impl Clone for Config

source§

fn clone(&self) -> Config

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Config

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Config

source§

fn default() -> Config

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Config

source§

fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
source§

impl FromStr for Config

source§

fn from_str(src: &str) -> Result<Self>

Load a Config from some string.

§

type Err = Error

The associated error which can be returned from parsing.
source§

impl PartialEq for Config

source§

fn eq(&self, other: &Config) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Config

source§

fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,