Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,22 @@ I am a Canadian who lives in Korea, and I wrote Easy Rust while thinking of how
- [Arrays](#arrays-1)
- [char](#char)
- [Integers](#integers)
- [Floats](#floats)
- [Bool](#bool)
- [Floats](#floats-1)
- [bool](#bool)
- [Vec](#vec)
- [String](#string)
- [OsString and CString](#osstring-and-cstring)
- [Mem](#mem)
- [Prelude](#prelude)
- [Time](#time)
- [Other-macros](#other-macros)
- [mem](#mem)
- [prelude](#prelude)
- [time](#time)
- [Other macros](#other-macros)
- [Writing macros](#writing-macros)
- [Part 2 - Rust on your computer](#part-2---rust-on-your-computer)
- [Cargo](#cargo)
- [Taking_user_input](#taking-user-input)
- [cargo](#cargo)
- [Taking user input](#taking-user-input)
- [Using files](#using-files)
- [Cargo doc](#cargo-doc)
- [The end?](#the-end?)
- [cargo doc](#cargo-doc)
- [The end?](#the-end)

# Part 1 - Rust in your browser

Expand Down Expand Up @@ -4510,6 +4510,28 @@ Err(ParseIntError { kind: InvalidDigit })
Ok(6060)
```

Recall previous chapter [32. Option and Result](https://dhghomon.github.io/easy_rust/Chapter_31.html)

Above code equivalent:

```rust
fn parse_str(input: &str) -> Result<i32, std::num::ParseIntError> {
let pv = match input.parse::<i32>() {
Ok(parsed_val) => parsed_val,
Err(err_info) => return Err(err_info)
};
Ok(pv)
}
fn main() {
let str_vec = vec!["Seven", "8", "9.0", "nice", "6060"];
for item in str_vec {
let parsed = parse_str(item);
println!("{:?}", parsed);
}
}

```

How did we find `std::num::ParseIntError`? One easy way is to "ask" the compiler again.

```rust
Expand Down