From 7a2dc713caa940ffc8404d2ce4fe940782bfe7f0 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Tue, 27 Aug 2024 04:51:45 +0000 Subject: [PATCH] Update Examples --- Examples.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Examples.md b/Examples.md index df2f490..60e0eef 100644 --- a/Examples.md +++ b/Examples.md @@ -910,7 +910,7 @@ fn main #### for loops -This subsection introduces the three ways of converting collections into iterators. For convenience, we combine them into a single example here. Note that in Husht you can select the mode of conversion by decorating the looping preposition `in`. +This subsection introduces the three ways of converting collections into iterators. For convenience, we combine them into a single example here. Note that we have changed the loop specifications in the examples on the Rust side, because it seems more Rust-idiomatic to (for example) iterate on a reference to a collection than to call .iter explicitly. @@ -924,7 +924,7 @@ This subsection introduces the three ways of converting collections into iterat fn main() { let mut names = vec!["Bob", "Frank", "Ferris"]; - for name in names.iter() { + for name in &names { match name { &"Ferris" => println!("Rustacean alert!"), _ => println!("Hello {}", name), @@ -933,7 +933,7 @@ fn main() { println!("names: {:?}", names); - for name in names.iter_mut() { + for name in &mut names { *name = match name { &mut "Ferris" => "Rustacean alert!", _ => "Hello", @@ -942,7 +942,7 @@ fn main() { println!("names: {:?}", names); - for name in names.into_iter() { + for name in names { match name { "Hello" => println!("Someone was normal"), _ => println!("Warning: {}", name), @@ -958,7 +958,7 @@ fn main() { fn main let mut names = vec!["Bob", "Frank", "Ferris"] - for name &in names + for name in &names match name &"Ferris" => println! "Rustacean alert!" _ => println! "Hello {}", name @@ -967,7 +967,7 @@ fn main - for name &mut in names + for name in &mut names *name = match name &mut "Ferris" => "Rustacean alert!" _ => "Hello"