From e81de8f24084a70cb967589341101517c632c349 Mon Sep 17 00:00:00 2001 From: shreepads Date: Sun, 6 Dec 2020 13:42:00 +0530 Subject: [PATCH 1/2] Clarify distinction between for iter and into_iter The existing code examples for `for iter` and `for into_iter` don't make the distinction very clear to the user. Although this is explained at the end, allowing the user experiment with the match types and showing how the collection gets consumed in `into_iter` but not in `iter` would help them understand better. --- src/flow_control/for.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/flow_control/for.md b/src/flow_control/for.md index 99e6458493..1e9191498d 100644 --- a/src/flow_control/for.md +++ b/src/flow_control/for.md @@ -67,9 +67,12 @@ fn main() { for name in names.iter() { match name { &"Ferris" => println!("There is a rustacean among us!"), + // TODO ^ Try deleting the & and matching just "Ferris" _ => println!("Hello {}", name), } } + + println!("names: {:?}", names); } ``` @@ -87,6 +90,9 @@ fn main() { _ => println!("Hello {}", name), } } + + println!("names: {:?}", names); + // FIXME ^ Comment out this line } ``` From 4cc85655b97be83acbca5d036cf679f39ea66eb8 Mon Sep 17 00:00:00 2001 From: shreepads Date: Sun, 6 Dec 2020 14:01:01 +0530 Subject: [PATCH 2/2] Fix for.md to ignore compiler error for FIXME The user needs to fix the section by commenting out `println!("names: {:?}", names);` before running the example --- src/flow_control/for.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flow_control/for.md b/src/flow_control/for.md index 1e9191498d..23445fe4fd 100644 --- a/src/flow_control/for.md +++ b/src/flow_control/for.md @@ -80,7 +80,7 @@ fn main() { data is provided. Once the collection has been consumed it is no longer available for reuse as it has been 'moved' within the loop. -```rust, editable +```rust, editable, ignore fn main() { let names = vec!["Bob", "Frank", "Ferris"];