mirror of
https://github.com/haraldh/chainerror.git
synced 2025-05-29 05:08:06 +02:00
add library chapter tutorial13
This commit is contained in:
parent
8bd4ffca56
commit
dfe97b34d6
3 changed files with 95 additions and 0 deletions
18
booksrc/tutorial13.md
Normal file
18
booksrc/tutorial13.md
Normal 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:}}
|
||||
~~~
|
Loading…
Add table
Add a link
Reference in a new issue