]> git.lizzy.rs Git - rust.git/commitdiff
Clarify the description for rfind
authorLynoure Braakman <lynoure@gmail.com>
Mon, 13 Jul 2020 15:41:27 +0000 (17:41 +0200)
committerLynoure Braakman <lynoure@gmail.com>
Mon, 13 Jul 2020 15:41:27 +0000 (17:41 +0200)
Changes the example code to illustrate the difference between
find and rfind

src/libcore/str/mod.rs

index 0014501d2c4d0624958317bcde37ecd587454180..fdcd56b9dffc0f5cc294ca5ae5c044723e96b6a9 100644 (file)
@@ -3158,11 +3158,11 @@ pub fn ends_with<'a, P>(&'a self, pat: P) -> bool
     /// Simple patterns:
     ///
     /// ```
-    /// let s = "Löwe 老虎 Léopard";
+    /// let s = "Löwe 老虎 Léopard Gepardi";
     ///
     /// assert_eq!(s.find('L'), Some(0));
     /// assert_eq!(s.find('é'), Some(14));
-    /// assert_eq!(s.find("Léopard"), Some(13));
+    /// assert_eq!(s.find("pard"), Some(17));
     /// ```
     ///
     /// More complex patterns using point-free style and closures:
@@ -3190,8 +3190,8 @@ pub fn find<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option<usize> {
         pat.into_searcher(self).next_match().map(|(i, _)| i)
     }
 
-    /// Returns the byte index of the last character of this string slice that
-    /// matches the pattern.
+    /// Returns the byte index for the first character of the rightmost match of the pattern in
+    /// this string slice.
     ///
     /// Returns [`None`] if the pattern doesn't match.
     ///
@@ -3207,10 +3207,11 @@ pub fn find<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option<usize> {
     /// Simple patterns:
     ///
     /// ```
-    /// let s = "Löwe 老虎 Léopard";
+    /// let s = "Löwe 老虎 Léopard Gepardi";
     ///
     /// assert_eq!(s.rfind('L'), Some(13));
     /// assert_eq!(s.rfind('é'), Some(14));
+    /// assert_eq!(s.rfind("pard"), Some(24));
     /// ```
     ///
     /// More complex patterns with closures: