Update Examples

Glen Whitney 2024-08-27 04:51:45 +00:00
parent 30948d0d4a
commit 7a2dc713ca

@ -910,7 +910,7 @@ fn main
</td></tr></table>
#### 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.
<table>
<tr>
@ -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"