book-ja icon indicating copy to clipboard operation
book-ja copied to clipboard

Add `dyn` keyword to `Box<Error>` type in Chapter 12

Open matsuokashuhei opened this issue 3 years ago • 1 comments

First of all, thanks for translating! It has helped me learn Rust.

Then I found a compile error while learning chapter 12.

error[E0782]: trait objects must include the `dyn` keyword
  --> src/main.rs:18:42
   |
18 | fn run(config: Config) -> Result<(), Box<Error>> {
   |                                          ^^^^^
   |
help: add `dyn` keyword before this trait
   |
18 - fn run(config: Config) -> Result<(), Box<Error>> {
18 + fn run(config: Config) -> Result<(), Box<dyn Error>> {
   | 

For more information about this error, try `rustc --explain E0782`.

Compared to the original, I found that the dyn keyword is missing. The exact original text is as follows, but the code and text have been changed to exclude annotations in the code such as [1].

https://github.com/rust-lang/book/blob/02a168ed34/nostarch/chapter12.md

For the error type, we used the *trait object* `Box<dyn Error>` (and we’ve
brought `std::error::Error` into scope with a `use` statement at the top [1]).
We’ll cover trait objects in Chapter 17. For now, just know that `Box<dyn
Error>` means the function will return a type that implements the `Error`
trait, but we don’t have to specify what particular type the return value will
be. This gives us flexibility to return error values that may be of different
types in different error cases. The `dyn` keyword is short for “dynamic.”

Thanks!

matsuokashuhei avatar Jun 26 '22 05:06 matsuokashuhei

レビューしてくれてありがとうございます!!!

matsuokashuhei avatar Aug 19 '22 16:08 matsuokashuhei

@tatsuya6502 thanks!!!!

matsuokashuhei avatar Sep 25 '22 10:09 matsuokashuhei