@@ -31,9 +31,9 @@ a [`RenderContext::from_json()`] constructor which will load a `RenderContext`.
31
31
32
32
This is all the boilerplate necessary for our backend to load the book.
33
33
34
- ``` rust
34
+ ``` rust,should_panic
35
+ # // this sample panics because it can't open stdin
35
36
// src/main.rs
36
- extern crate mdbook;
37
37
38
38
use std::io;
39
39
use mdbook::renderer::RenderContext;
@@ -55,14 +55,18 @@ fn main() {
55
55
56
56
## Inspecting the Book
57
57
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
59
59
chapter!
60
60
61
61
Because the ` RenderContext ` contains a [ ` Book ` ] field (` book ` ), and a ` Book ` has
62
62
the [ ` Book::iter() ` ] method for iterating over all items in a ` Book ` , this step
63
63
turns out to be just as easy as the first.
64
64
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};
66
70
67
71
fn main() {
68
72
let mut stdin = io::stdin();
@@ -174,26 +178,25 @@ deserializing to some arbitrary type `T`.
174
178
To implement this, we'll create our own serializable ` WordcountConfig ` struct
175
179
which will encapsulate all configuration for this backend.
176
180
177
- First add ` serde ` and ` serde_derive ` to your ` Cargo.toml ` ,
181
+ First add ` serde ` to your ` Cargo.toml ` ,
178
182
179
- ```
180
- $ cargo add serde serde_derive
183
+ ``` shell
184
+ $ cargo add serde
181
185
```
182
186
183
187
And then you can create the config struct,
184
188
185
189
``` rust
186
- extern crate serde;
187
- #[macro_use]
188
- extern crate serde_derive;
190
+ use serde :: {Serialize , Deserialize };
189
191
190
- ...
192
+ fn main () {
191
193
192
194
#[derive(Debug , Default , Serialize , Deserialize )]
193
195
#[serde(default, rename_all = " kebab-case" )]
194
196
pub struct WordcountConfig {
195
197
pub ignores : Vec <String >,
196
198
}
199
+ }
197
200
```
198
201
199
202
Now we just need to deserialize the ` WordcountConfig ` from our ` RenderContext `
0 commit comments