book: use rustdoc_include

This commit is contained in:
Harald Hoyer 2020-03-03 14:25:37 +01:00
parent 903f245278
commit 3e270f1e1a
No known key found for this signature in database
GPG key ID: 340F12141EA0994D
14 changed files with 15 additions and 626 deletions

View file

@ -17,10 +17,10 @@ and improves inspecting the sources of an error.
You can also run the tutorial examples in the checked out
[chainerror git repo](https://github.com/haraldh/chainerror).
~~~
~~~console
$ cargo run -q --example tutorial1
~~~
~~~rust
{{#include ../examples/tutorial1.rs}}
~~~
~~~

View file

@ -20,6 +20,6 @@ Also a nice `match` on `ChainError<T>.kind()` is now possible, which returns `&T
{{#include ../examples/tutorial10.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#includecomment ../src/lib.rs}}
{{#rustdoc_include ../src/lib.rs:-1}}
# }
~~~

View file

@ -28,6 +28,6 @@ which can then be used with `chainerror`.
{{#include ../examples/tutorial11.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#includecomment ../src/lib.rs}}
{{#rustdoc_include ../src/lib.rs:-1}}
# }
~~~

View file

@ -6,6 +6,6 @@ or call a function with `&e`
{{#include ../examples/tutorial12.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#includecomment ../src/lib.rs}}
{{#rustdoc_include ../src/lib.rs:-1}}
# }
~~~

View file

@ -10,7 +10,7 @@ have to change much or anything.
# #[allow(dead_code)]
# #[macro_use]
# pub mod chainerror {
{{#includecomment ../src/lib.rs}}
{{#rustdoc_include ../src/lib.rs:-1}}
# }
pub mod mycrate {
use crate::chainerror::*; // omit the `crate::` part

View file

@ -9,7 +9,7 @@ Press the play button in the upper right corner and see the nice debug output.
{{#include ../examples/tutorial2.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#includecomment ../src/lib.rs}}
{{#rustdoc_include ../src/lib.rs:-1}}
# }
~~~
@ -29,4 +29,4 @@ again have a `Err(Box<Error + Send + Sync>)` as a result.
The `Debug` implementation of `ChainError<T>` (which is returned by `cherr!()`)
prints the `Debug` of `T` prefixed with the stored filename and line number.
`ChainError<T>` in our case is `ChainError<String>`.
`ChainError<T>` in our case is `ChainError<String>`.

View file

@ -6,7 +6,7 @@ Now let's get more rust idiomatic by using `.map_err()`.
{{#include ../examples/tutorial3.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#includecomment ../src/lib.rs}}
{{#rustdoc_include ../src/lib.rs:-1}}
# }
~~~

View file

@ -12,6 +12,6 @@ more debug strings.
{{#include ../examples/tutorial4.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#includecomment ../src/lib.rs}}
{{#rustdoc_include ../src/lib.rs:-1}}
# }
~~~

View file

@ -7,7 +7,7 @@ Sometimes you want to inspect the `source()` of an `Error`.
{{#include ../examples/tutorial5.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#includecomment ../src/lib.rs}}
{{#rustdoc_include ../src/lib.rs:-1}}
# }
~~~

View file

@ -14,6 +14,6 @@ This is how it looks like, when using those:
{{#include ../examples/tutorial6.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#includecomment ../src/lib.rs}}
{{#rustdoc_include ../src/lib.rs:-1}}
# }
~~~

View file

@ -30,6 +30,6 @@ or to use `.root_cause()`, which of course can be of any type implementing `std:
{{#include ../examples/tutorial7.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#includecomment ../src/lib.rs}}
{{#rustdoc_include ../src/lib.rs:-1}}
# }
~~~

View file

@ -26,6 +26,6 @@ hiding the `ChainError<T>` implementation detail.
{{#include ../examples/tutorial8.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#includecomment ../src/lib.rs}}
{{#rustdoc_include ../src/lib.rs:-1}}
# }
~~~

View file

@ -28,6 +28,6 @@ In the next chapter, we will see, how to solve this more elegantly.
{{#include ../examples/tutorial9.rs}}
# #[allow(dead_code)]
# mod chainerror {
{{#includecomment ../src/lib.rs}}
{{#rustdoc_include ../src/lib.rs:-1}}
# }
~~~