From da7aab6e51fd06ea6628324b3be5ab88a4abda4f Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 17 Oct 2017 20:11:03 -0500 Subject: added examples of closures --- src/liballoc/str.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/liballoc') diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 830128f2b9f..3e273a67000 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -959,13 +959,15 @@ impl str { /// assert_eq!(s.find("Léopard"), Some(13)); /// ``` /// - /// More complex patterns with closures: + /// More complex patterns using point-free style and closures: /// /// ``` /// let s = "Löwe 老虎 Léopard"; /// /// assert_eq!(s.find(char::is_whitespace), Some(5)); /// assert_eq!(s.find(char::is_lowercase), Some(1)); + /// assert_eq!(s.find(|c: char| c.is_whitespace()), Some(5)); + /// assert_eq!(s.find(|c: char| c.is_lowercase()), Some(1)); /// ``` /// /// Not finding the pattern: -- cgit 1.4.1-3-g733a5 From 2a889eb945cdae95fce33fbeb1b79093c456cadd Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Tue, 17 Oct 2017 23:51:27 -0500 Subject: added non trivial examples of closures for str::find --- src/liballoc/str.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 3e273a67000..895607ff8d4 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -966,8 +966,8 @@ impl str { /// /// assert_eq!(s.find(char::is_whitespace), Some(5)); /// assert_eq!(s.find(char::is_lowercase), Some(1)); - /// assert_eq!(s.find(|c: char| c.is_whitespace()), Some(5)); - /// assert_eq!(s.find(|c: char| c.is_lowercase()), Some(1)); + /// assert_eq!(s.find(|c: char| c.is_whitespace() || c.is_lowercase()), Some(1)); + /// assert_eq!(s.find(|c: char| (c < 'o') && (c > 'a')), Some(4)); /// ``` /// /// Not finding the pattern: -- cgit 1.4.1-3-g733a5