From e35e0e1039bd1ad2bdc0de9ec1e45568d11cd4ca Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 25 Aug 2016 16:30:50 -0400 Subject: [PATCH] Remove 'creating your own error types' this should end up later in the book, someday --- src/SUMMARY.md | 1 - src/ch07-03-recoverable-errors-with-result.md | 3 ++ src/ch07-04-creating-your-own-error-types.md | 34 ------------------- 3 files changed, 3 insertions(+), 35 deletions(-) delete mode 100644 src/ch07-04-creating-your-own-error-types.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 2583ec7..1eb7961 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -6,7 +6,6 @@ - [Guessing Game Tutorial](ch02-00-guessing-game-tutorial.md) -<<<<<<< a2bc57618340b6257b9a4dd7d4f3993c71cde2e4 - [Common Programming Concepts in Rust](ch03-00-common-programming-concepts-in-rust.md) - [Variable Bindings and Mutability](ch03-01-variable-bindings-and-mutability.md) - [Data Types](ch03-02-data-types.md) diff --git a/src/ch07-03-recoverable-errors-with-result.md b/src/ch07-03-recoverable-errors-with-result.md index 9b63e4a..30ef1a3 100644 --- a/src/ch07-03-recoverable-errors-with-result.md +++ b/src/ch07-03-recoverable-errors-with-result.md @@ -175,3 +175,6 @@ effects; nothing is returned upon success. Well, functions with no return type, as we just saw with `main()`, are the same as returning unit. So we can use it as the return type here, too. This leads to the last line of the function, the slightly silly-looking `Ok(())`. This is an `Ok()` with a `()` inside. + +In chapter XX, we'll learn how to make our own types like these, but for now, +an understanding of the core `Result` is enough. diff --git a/src/ch07-04-creating-your-own-error-types.md b/src/ch07-04-creating-your-own-error-types.md deleted file mode 100644 index 0e56945..0000000 --- a/src/ch07-04-creating-your-own-error-types.md +++ /dev/null @@ -1,34 +0,0 @@ -# Creating your own Error types - -This pattern of "return an error" is so common, many libraries create their -own error type, and use it for all of their functions. We can re-write the -previous example to use `std::io::Result` rathern than a regular `Result`: - -```rust -#![feature(question_mark)] - -use std::fs::File; -use std::io; - -fn main() { -} - -pub fn process_file() -> io::Result<()> { - let f = File::open("hello.txt")?; - - // do some stuff with f - - Ok(()) -} -``` - -`io::Result` looks like this: - -```rust -# use std::io; -type Result = Result; -``` - -It's a type alias for a regular-old `Result`, with the `E` set up to be a -`std::io::Error`. This means we don't need to worry about the error type in our -function signatures, which is nice.