Struct mdbook::config::Config[][src]

pub struct Config {
    pub book: BookConfig,
    pub build: BuildConfig,
    pub rust: RustConfig,
    // some fields omitted
}

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

impl Config[src]

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

Load the configuration file from disk.

pub fn update_from_env(&mut self)[src]

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.

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

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

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

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

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

👎 Deprecated:

use get_deserialized_opt instead

Deprecated, use get_deserialized_opt instead.

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

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

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

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.

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

Get the table associated with a particular renderer.

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

Get the table associated with a particular preprocessor.

Trait Implementations

impl Clone for Config[src]

fn clone(&self) -> Config[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Config[src]

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

Formats the value using the given formatter. Read more

impl Default for Config[src]

fn default() -> Config[src]

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

impl<'de> Deserialize<'de> for Config[src]

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

Deserialize this value from the given Serde deserializer. Read more

impl FromStr for Config[src]

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

Load a Config from some string.

type Err = Error

The associated error which can be returned from parsing.

impl PartialEq<Config> for Config[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Config) -> bool[src]

This method tests for !=.

impl Serialize for Config[src]

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

Serialize this value into the given Serde serializer. Read more

impl StructuralPartialEq for Config[src]

Auto Trait Implementations

impl RefUnwindSafe for Config

impl Send for Config

impl Sync for Config

impl Unpin for Config

impl UnwindSafe for Config

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V

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