Skip to content

Commit

Permalink
add to SUMMARY.md, add rust [], ignore to snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelraz committed Jan 21, 2025
1 parent 8651fa9 commit a014833
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions exercise-book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Fizzbuzz with match](./fizzbuzz-match.md)
- [Rust Latin](./rustlatin.md)
- [URLs, match, result](./urls-match-result.md)
- [Iterators](./iterators.md)
- [SimpleDB](./simple-db.md)
- [Knowledge](./simple-db-knowledge.md)
- [Step-by-Step Solution](./simple-db-solution.md)
Expand Down
18 changes: 9 additions & 9 deletions exercise-book/src/iterators.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ X
- Place the above multi-line string into `iterators/numbers.txt`.
- Drop this snippet into your `src/main.rs`:

```rust
```rust [], ignore
#![allow(unused_imports)]
use std::io::BufReader;
use std::fs::File;
Expand Down Expand Up @@ -74,7 +74,7 @@ This lets us have a type safe way of composing control flow together by calling

For example, to double every number given by a vector, you could write a for loop:

```rust
```rust [], ignore
let v = [10, 20, 30];
let mut xs = [0, 0, 0];

Expand All @@ -85,7 +85,7 @@ for idx in 0..=v.len() {

In this case, the idea of the procedure `2 * v[idx]` and indexing over the entire collection is called a [map](https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.map). An idiomatic Rustacean would write something similar to the following (period indented) code:

```rust
```rust [], ignore
let v = [10, 20, 30];
let xs: Vec<_> = v.iter()
.map(|elem| elem * 2)
Expand All @@ -112,7 +112,7 @@ When in doubt, write `.map(|x| x)` first to see what item types you get and deci

Iterators sometimes struggle to figure out the types of all intermediate steps and need assistance.

```rust
```rust [], ignore
let numbers: Vec<_> = ["1", "2", "3"]
.iter()
.map(|s| s.parse::<i32>().unwrap())
Expand Down Expand Up @@ -166,7 +166,7 @@ Remember you can select and hover over each expression and rust-analyzer will di

Not all iterator chains operate on a single iterable at a time. This may mean joining several iterators and processing them together by destructuring a tuple when declaring the closure:

```rust
```rust [], ignore
let x = [10, 20, 30];
let y = [1, 2, 3];
let z = x.iter().zip(y.iter())
Expand Down Expand Up @@ -229,7 +229,7 @@ Collect it into a string with `.collect::<String>()` and print it to verify you'

We'll get rid of the `.unwrap()` in the next section.

```rust
```rust [], ignore
#![allow(unused_imports)]
use std::io::{BufRead, BufReader};
use std::fs::File;
Expand Down Expand Up @@ -263,7 +263,7 @@ Note that you may or may not need type annotations on `.parse()` depending on if

If the use of `filter_map` here is unfamiliar, go back and reread the ``Dealing with .unwrap()s in iterator chains`` section.

```rust
```rust [], ignore
#![allow(unused_imports)]
use std::io::{BufRead, BufReader};
use std::fs::File;
Expand Down Expand Up @@ -293,7 +293,7 @@ Use a [.filter()](https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#
<details>
<summary>Solution</summary>

```rust
```rust [], ignore
#![allow(unused_imports)]
use std::io::{BufRead, BufReader};
use std::fs::File;
Expand Down Expand Up @@ -327,7 +327,7 @@ You will probably reach for a `.sum::<i32>()`, but `.fold()`s are common enough
<details>
<summary>Solution</summary>

```rust
```rust [], ignore
#![allow(unused_imports)]
use std::io::{BufRead, BufReader};
use std::fs::File;
Expand Down

0 comments on commit a014833

Please sign in to comment.