Skip to content

Commit 38eecb8

Browse files
Added a couple notes and doc-comments
1 parent fe6c1c1 commit 38eecb8

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/book/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl MDBook {
273273
self.root.join(&self.config.book.src)
274274
}
275275

276-
// FIXME: This belongs as part of the `HtmlConfig`.
276+
// FIXME: This really belongs as part of the `HtmlConfig`.
277277
#[doc(hidden)]
278278
pub fn theme_dir(&self) -> PathBuf {
279279
match self.config.html_config().and_then(|h| h.theme) {

src/config.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ impl Config {
5454
/// # Note
5555
///
5656
/// This is for compatibility only. It will be removed completely once the
57-
/// rendering and plugin system is established.
57+
/// HTML renderer is refactored to be less coupled to `mdbook` internals.
58+
#[doc(hidden)]
5859
pub fn html_config(&self) -> Option<HtmlConfig> {
5960
self.get_deserialized("output.html").ok()
6061
}
@@ -75,6 +76,9 @@ impl Config {
7576
}
7677

7778
/// Set a config key, clobbering any existing values along the way.
79+
///
80+
/// The only way this can fail is if we can't serialize `value` into a
81+
/// `toml::Value`.
7882
pub fn set<S: Serialize, I: AsRef<str>>(&mut self, index: I, value: S) -> Result<()> {
7983
let pieces: Vec<_> = index.as_ref().split(".").collect();
8084
let value =
@@ -123,6 +127,11 @@ impl Config {
123127
}
124128
}
125129

130+
/// Recursively walk down a table and try to set some `foo.bar.baz` value.
131+
///
132+
/// If at any table along the way doesn't exist (or isn't itself a `Table`!) an
133+
/// empty `Table` will be inserted. e.g. if the `foo` table didn't contain a
134+
/// nested table called `bar`, we'd insert one and then keep recursing.
126135
fn recursive_set(key: &[&str], table: &mut Table, value: Value) {
127136
if key.is_empty() {
128137
unreachable!();
@@ -143,6 +152,7 @@ fn recursive_set(key: &[&str], table: &mut Table, value: Value) {
143152
}
144153
}
145154

155+
/// The "getter" version of `recursive_set()`.
146156
fn recursive_get<'a>(key: &[&str], table: &'a Table) -> Option<&'a Value> {
147157
if key.is_empty() {
148158
return None;
@@ -160,6 +170,7 @@ fn recursive_get<'a>(key: &[&str], table: &'a Table) -> Option<&'a Value> {
160170
}
161171
}
162172

173+
/// The mutable version of `recursive_get()`.
163174
fn recursive_get_mut<'a>(key: &[&str], table: &'a mut Table) -> Option<&'a mut Value> {
164175
// TODO: Figure out how to abstract over mutability to reduce copy-pasta
165176
if key.is_empty() {
@@ -248,7 +259,6 @@ fn is_legacy_format(table: &Table) -> bool {
248259
.any(|key| table.contains_key(&key.to_string()))
249260
}
250261

251-
252262
/// Configuration options which are specific to the book and required for
253263
/// loading it from disk.
254264
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@@ -308,7 +318,7 @@ pub struct HtmlConfig {
308318
pub additional_css: Vec<PathBuf>,
309319
pub additional_js: Vec<PathBuf>,
310320
pub playpen: Playpen,
311-
/// This is used as a bit of a workaround for the `mdbook serve` command.
321+
/// This is used as a bit of a workaround for the `mdbook serve` command.
312322
/// Basically, because you set the websocket port from the command line, the
313323
/// `mdbook serve` command needs a way to let the HTML renderer know where
314324
/// to point livereloading at, if it has been enabled.
@@ -335,7 +345,6 @@ impl Default for Playpen {
335345
}
336346
}
337347

338-
339348
#[cfg(test)]
340349
mod tests {
341350
use super::*;

0 commit comments

Comments
 (0)