add library chapter tutorial13

This commit is contained in:
Harald Hoyer 2019-03-04 11:38:11 +01:00
parent 8bd4ffca56
commit dfe97b34d6
No known key found for this signature in database
GPG key ID: 340F12141EA0994D
3 changed files with 95 additions and 0 deletions

18
booksrc/tutorial13.md Normal file
View file

@ -0,0 +1,18 @@
# Writing a library
I would advise to only expose an `mycrate::ErrorKind` and type alias `mycrate::Error` to `ChainError<mycrate::ErrorKind>`
so you can tell your library users to use the `.kind()` method as `std::io::Error` does.
If you later decide to make your own `Error` implementation, your library users don't
have to change much or anything.
~~~rust
# #[allow(dead_code)]
# #[macro_use]
# pub mod chainerror {
{{#includecomment ../src/lib.rs}}
# }
pub mod mycrate {
use crate::chainerror::*; // omit the `crate::` part
{{#include ../examples/tutorial13.rs:3:}}
~~~