Skip to content

Commit a3fc58b

Browse files
committed
fix `mdbook test <path/to/root>;
make chap Alternate Backends pass doctest.
1 parent 658221c commit a3fc58b

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

guide/src/for_developers/backends.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ a [`RenderContext::from_json()`] constructor which will load a `RenderContext`.
3131

3232
This is all the boilerplate necessary for our backend to load the book.
3333

34-
```rust
34+
```rust,should_panic
35+
# // this sample panics because it can't open stdin
3536
// src/main.rs
36-
extern crate mdbook;
3737
3838
use std::io;
3939
use mdbook::renderer::RenderContext;
@@ -55,14 +55,18 @@ fn main() {
5555

5656
## Inspecting the Book
5757

58-
Now our backend has a copy of the book, lets count how many words are in each
58+
Now our backend has a copy of the book, let's count how many words are in each
5959
chapter!
6060

6161
Because the `RenderContext` contains a [`Book`] field (`book`), and a `Book` has
6262
the [`Book::iter()`] method for iterating over all items in a `Book`, this step
6363
turns out to be just as easy as the first.
6464

65-
```rust
65+
```rust,should_panic
66+
# // this sample panics because it can't open stdin
67+
use std::io;
68+
use mdbook::renderer::RenderContext;
69+
use mdbook::book::{BookItem, Chapter};
6670
6771
fn main() {
6872
let mut stdin = io::stdin();
@@ -174,26 +178,25 @@ deserializing to some arbitrary type `T`.
174178
To implement this, we'll create our own serializable `WordcountConfig` struct
175179
which will encapsulate all configuration for this backend.
176180

177-
First add `serde` and `serde_derive` to your `Cargo.toml`,
181+
First add `serde` to your `Cargo.toml`,
178182

179-
```
180-
$ cargo add serde serde_derive
183+
```shell
184+
$ cargo add serde
181185
```
182186

183187
And then you can create the config struct,
184188

185189
```rust
186-
extern crate serde;
187-
#[macro_use]
188-
extern crate serde_derive;
190+
use serde::{Serialize, Deserialize};
189191

190-
...
192+
fn main() {
191193

192194
#[derive(Debug, Default, Serialize, Deserialize)]
193195
#[serde(default, rename_all = "kebab-case")]
194196
pub struct WordcountConfig {
195197
pub ignores: Vec<String>,
196198
}
199+
}
197200
```
198201

199202
Now we just need to deserialize the `WordcountConfig` from our `RenderContext`

src/book/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl MDBook {
310310

311311
let mut extern_args = ExternArgs::new();
312312
if let Some(manifest) = &self.config.rust.manifest {
313-
extern_args.load(&manifest)?;
313+
extern_args.load(&self.root.join(manifest))?;
314314
}
315315

316316
let mut failed = false;

0 commit comments

Comments
 (0)