Skip to content

Conversation

@veggiemonk
Copy link
Contributor

Add Result type signature as it is difficult for new comers to understand Generics and Error all at once.

At first, I tried Result<String, Error> and got this.

error[E0412]: cannot find type `Error` in this scope
 --> exercises/error_handling/errors1.rs:9:62
  |
9 | pub fn generate_nametag_text(name: String) -> Result<String, Error> {
  |                                                              ^^^^^ not found in this scope
help: possible candidates are found in other modules, you can import them into scope
  |
1 | use std::error::Error;
  |
1 | use std::fmt::Error;
  |
1 | use std::io::Error;
  |

In the book, it talks about std::io::Error with Result which is a bit confusing. See https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html

It took me a long time to understand that Result can take whatever type as a second argument.

Let me know your thoughts on how to improve this.

Add Result type signature as it is difficult for new comers to understand Generics and Error all at once
@veggiemonk veggiemonk changed the title Update errors1.rs Update errors1.rs - Add Result type signature as it is difficult for new comers to understand Generics and Error all at once. May 12, 2019
Copy link
Contributor

@komaeda komaeda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@komaeda komaeda merged commit 5423bc6 into rust-lang:master May 22, 2019
ppp3 pushed a commit to ppp3/rustlings that referenced this pull request May 23, 2022
…new comers to understand Generics and Error all at once. (rust-lang#157)

Update errors1.rs - Add Result type signature as it is difficult for new comers to understand Generics and Error all at once.
dmoore04 pushed a commit to dmoore04/rustlings that referenced this pull request Sep 11, 2022
…new comers to understand Generics and Error all at once. (rust-lang#157)

Update errors1.rs - Add Result type signature as it is difficult for new comers to understand Generics and Error all at once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants