mirror of
https://github.com/rust-lang/book.git
synced 2026-11-30 21:51:17 -06:00
Add a summary
This commit is contained in:
@@ -149,5 +149,16 @@ would not need to do any additional checks in its body.
|
||||
|
||||
## Summary
|
||||
|
||||
Now that we've reduced duplication in our validation code, let's look at a
|
||||
feature of Rust that helps reduce duplication in lots of code: generics!
|
||||
Rust's error handling features are designed to help you write more robust code.
|
||||
The `panic!` macro signals that your program is in a state it can't handle, and
|
||||
lets you tell the process to stop instead of trying to proceed with invalid or
|
||||
incorrect values. The `Result` enum uses Rust's type system as a sign that
|
||||
operations you call might fail in a way that your code could recover from. You
|
||||
can use `Result` to tell code that calls yours that it needs to handle
|
||||
potential success or failure as well. Using `panic!` and `Result` in the
|
||||
appropriate situations will help your code be more reliable in the face of
|
||||
inevitable problems.
|
||||
|
||||
Now that we've seen useful ways that the standard library uses generics with
|
||||
the `Option` and `Result` enums, let's talk about how generics work and how you
|
||||
can make use of them in your code.
|
||||
|
||||
Reference in New Issue
Block a user