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: 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: AsRef<Path>>(config_file: P) -> Result<Config>
pub fn from_disk<P: AsRef<Path>>(config_file: P) -> Result<Config>
Load the configuration file from disk.
Sourcepub fn update_from_env(&mut self)
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->fooMDBOOK_FOO->fooMDBOOK_FOO__BAR->foo.barMDBOOK_FOO_BAR->foo-barMDBOOK_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.
Sourcepub fn get(&self, key: &str) -> Option<&Value>
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).
Sourcepub fn get_mut(&mut self, key: &str) -> Option<&mut Value>
pub fn get_mut(&mut self, key: &str) -> Option<&mut Value>
Fetch a value from the Config so you can mutate it.
Sourcepub fn get_deserialized<'de, T: Deserialize<'de>, S: AsRef<str>>(
&self,
name: S,
) -> Result<T>
👎Deprecated: use get_deserialized_opt instead
pub fn get_deserialized<'de, T: Deserialize<'de>, S: AsRef<str>>( &self, name: S, ) -> Result<T>
Deprecated, use get_deserialized_opt instead.
Sourcepub fn get_deserialized_opt<'de, T: Deserialize<'de>, S: AsRef<str>>(
&self,
name: S,
) -> Result<Option<T>>
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.
Sourcepub fn set<S: Serialize, I: AsRef<str>>(
&mut self,
index: I,
value: S,
) -> Result<()>
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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
impl StructuralPartialEq for Config
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)