Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit e837fe1

Browse files
committed
Enable more doctests.
1 parent bce3d99 commit e837fe1

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

src/lib.rs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,17 @@
6666
//!
6767
//! Write this at the top of your crate:
6868
//!
69-
//! ```ignore
69+
//! ```
7070
//! #![recursion_limit = "1024"]
71+
//! # fn main() {}
7172
//! ```
7273
//!
7374
//! Again near the top of your crate, import the `error_chain` crate and its macros:
7475
//!
75-
//! ```ignore
76+
//! ```
7677
//! #[macro_use]
7778
//! extern crate error_chain;
79+
//! # fn main() {}
7880
//! ```
7981
//!
8082
//! Add an `errors` module to your crate:
@@ -85,7 +87,9 @@
8587
//!
8688
//! Add a file for that module called `errors.rs` and put this inside:
8789
//!
88-
//! ```ignore
90+
//! ```
91+
//! # #[macro_use] extern crate error_chain;
92+
//! # fn main() {}
8993
//! error_chain! { }
9094
//! ```
9195
//!
@@ -100,6 +104,12 @@
100104
//! the `error_chain!` macro, and start chaining errors!
101105
//!
102106
//! ```ignore
107+
//! # #[macro_use] extern crate error_chain;
108+
//! # use std::fs::File;
109+
//! # use std::io::Write;
110+
//! # use error_chain::ResultExt;
111+
//! # fn main() {}
112+
//! # error_chain! {}
103113
//! fn do_error_prone_work() -> Result<()> {
104114
//! let file = try!(File::open("foo").chain_err(|| "couldn't open file"));
105115
//! try!(file.write_all("important".as_bytes()).chain_err(|| "couldn't write file"));
@@ -192,9 +202,10 @@
192202
//! use std::sync::Arc;
193203
//!
194204
//! #[derive(Debug)]
195-
//! pub struct Error(pub ErrorKind,
196-
//! pub Option<Box<StdError + Send>>,
197-
//! pub Option<Arc<error_chain::Backtrace>>);
205+
//! pub struct Error {
206+
//! pub kind: ErrorKind,
207+
//! pub state: ::error_chain::State,
208+
//! }
198209
//!
199210
//! impl Error {
200211
//! pub fn kind(&self) -> &ErrorKind { ... }
@@ -238,15 +249,24 @@
238249
//!
239250
//! Introducing new error chains, with a string message:
240251
//!
241-
//! ```ignore
252+
//! ```
253+
//! # #[macro_use] extern crate error_chain;
254+
//! # fn main() {}
255+
//! # error_chain! {}
242256
//! fn foo() -> Result<()> {
243257
//! Err("foo error!".into())
244258
//! }
245259
//! ```
246260
//!
247261
//! Introducing new error chains, with an `ErrorKind`:
248262
//!
249-
//! ```ignore
263+
//! ```
264+
//! # #[macro_use] extern crate error_chain;
265+
//! # fn main() {}
266+
//! error_chain! {
267+
//! errors { FooError }
268+
//! }
269+
//!
250270
//! fn foo() -> Result<()> {
251271
//! Err(ErrorKind::FooError.into())
252272
//! }
@@ -264,7 +284,10 @@
264284
//! automatically convert `Err(ErrorKind)` to `Err(Error)`. So the
265285
//! below is equivalent to the previous:
266286
//!
267-
//! ```ignore
287+
//! ```
288+
//! # #[macro_use] extern crate error_chain;
289+
//! # fn main() {}
290+
//! # error_chain! { errors { FooError } }
268291
//! fn foo() -> Result<()> {
269292
//! Ok(try!(Err(ErrorKind::FooError)))
270293
//! }
@@ -278,9 +301,16 @@
278301
//!
279302
//! To extend the error chain:
280303
//!
281-
//! ```ignore
304+
//! ```
305+
//! # #[macro_use] extern crate error_chain;
306+
//! # fn main() {}
307+
//! # error_chain! {}
308+
//! # fn do_something() -> Result<()> { unimplemented!() }
309+
//! # fn test() -> Result<()> {
282310
//! use error_chain::ResultExt;
283-
//! try!(do_something().chain_err(|| "something went wrong"));
311+
//! let res: Result<()> = do_something().chain_err(|| "something went wrong");
312+
//! # Ok(())
313+
//! # }
284314
//! ```
285315
//!
286316
//! `chain_err` can be called on any `Result` type where the contained

0 commit comments

Comments
 (0)