From 58830fc524af696d286e8795cdd5f6cfa7c80d80 Mon Sep 17 00:00:00 2001 From: Tiziano Santoro Date: Mon, 2 Nov 2020 14:30:58 +0000 Subject: [PATCH] Clarify slice patterns example The previous phrasing was not precise enough, and suggested that the `[first, second]` pattern would match any slice with at least two elements, while in fact it only matches slices with exactly two elements. --- src/rust-2018/slice-patterns.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rust-2018/slice-patterns.md b/src/rust-2018/slice-patterns.md index 6e62e0fe..a69dba15 100644 --- a/src/rust-2018/slice-patterns.md +++ b/src/rust-2018/slice-patterns.md @@ -15,7 +15,7 @@ fn main() { greet(&["Alan"]); // output: Hey, there Alan! You seem to be alone. greet(&["Joan", "Hugh"]); - // output: Hello, Joan and Hugh. Nice to see you are at least 2! + // output: Hello, Joan and Hugh. Nice to see you are exactly 2! greet(&["John", "Peter", "Stewart"]); // output: Hey everyone, we seem to be 3 here today. } @@ -25,7 +25,7 @@ fn greet(people: &[&str]) { [] => println!("Bummer, there's no one here :("), [only_one] => println!("Hey, there {}! You seem to be alone.", only_one), [first, second] => println!( - "Hello, {} and {}. Nice to see you are at least 2!", + "Hello, {} and {}. Nice to see you are exactly 2!", first, second ), _ => println!("Hey everyone, we seem to be {} here today.", people.len()), @@ -88,4 +88,4 @@ error[E0527]: pattern requires 4 elements but array has 3 [the tracking issue]: https://github.com/rust-lang/rust/issues/23121 When it comes to slice patterns, more advanced forms are planned but -have not been stabilized yet. To learn more, follow [the tracking issue]. \ No newline at end of file +have not been stabilized yet. To learn more, follow [the tracking issue].