From 8f99ad2a2a8a95b395de93d692f1b652721e94c8 Mon Sep 17 00:00:00 2001 From: Kevin Brothaler Date: Fri, 18 Mar 2016 11:19:20 -0400 Subject: [PATCH] Update of the book; Error handling, section on custom error types: we should also show the changes to the `cause` method. --- src/doc/book/error-handling.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/doc/book/error-handling.md b/src/doc/book/error-handling.md index 11086af10bd3d..12cb71973ab25 100644 --- a/src/doc/book/error-handling.md +++ b/src/doc/book/error-handling.md @@ -2019,6 +2019,16 @@ impl Error for CliError { CliError::NotFound => "not found", } } + + fn cause(&self) -> Option<&error::Error> { + match *self { + CliError::Io(ref err) => Some(err), + CliError::Parse(ref err) => Some(err), + // Our custom error doesn't have an underlying cause, but we could + // modify it so that it does. + CliError::NotFound() => None, + } + } } ```