@@ -451,7 +451,13 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
451451
452452impl < ' a > DoubleEndedSearcher < ' a > for CharSearcher < ' a > { }
453453
454- /// Searches for chars that are equal to a given char
454+ /// Searches for chars that are equal to a given `char`.
455+ ///
456+ /// # Examples
457+ ///
458+ /// ```
459+ /// assert_eq!("Hello world".find('o'), Some(4));
460+ /// ```
455461impl < ' a > Pattern < ' a > for char {
456462 type Searcher = CharSearcher < ' a > ;
457463
@@ -696,7 +702,14 @@ unsafe impl<'a, 'b> ReverseSearcher<'a> for CharSliceSearcher<'a, 'b> {
696702
697703impl < ' a , ' b > DoubleEndedSearcher < ' a > for CharSliceSearcher < ' a , ' b > { }
698704
699- /// Searches for chars that are equal to any of the chars in the array
705+ /// Searches for chars that are equal to any of the chars in the array.
706+ ///
707+ /// # Examples
708+ ///
709+ /// ```
710+ /// assert_eq!("Hello world".find(&['l', 'l'] as &[_]), Some(2));
711+ /// assert_eq!("Hello world".find(&['l', 'l'][..]), Some(2));
712+ /// ```
700713impl < ' a , ' b > Pattern < ' a > for & ' b [ char ] {
701714 pattern_methods ! ( CharSliceSearcher <' a, ' b>, MultiCharEqPattern , CharSliceSearcher ) ;
702715}
@@ -738,7 +751,14 @@ where
738751
739752impl < ' a , F > DoubleEndedSearcher < ' a > for CharPredicateSearcher < ' a , F > where F : FnMut ( char ) -> bool { }
740753
741- /// Searches for chars that match the given predicate
754+ /// Searches for chars that match the given predicate.
755+ ///
756+ /// # Examples
757+ ///
758+ /// ```
759+ /// assert_eq!("Hello world".find(char::is_uppercase), Some(0));
760+ /// assert_eq!("Hello world".find(|c| "aeiou".contains(c)), Some(1));
761+ /// ```
742762impl < ' a , F > Pattern < ' a > for F
743763where
744764 F : FnMut ( char ) -> bool ,
@@ -763,6 +783,12 @@ impl<'a, 'b, 'c> Pattern<'a> for &'c &'b str {
763783///
764784/// Will handle the pattern `""` as returning empty matches at each character
765785/// boundary.
786+ ///
787+ /// # Examples
788+ ///
789+ /// ```
790+ /// assert_eq!("Hello world".find("world"), Some(6));
791+ /// ```
766792impl < ' a , ' b > Pattern < ' a > for & ' b str {
767793 type Searcher = StrSearcher < ' a , ' b > ;
768794
@@ -771,7 +797,7 @@ impl<'a, 'b> Pattern<'a> for &'b str {
771797 StrSearcher :: new ( haystack, self )
772798 }
773799
774- /// Checks whether the pattern matches at the front of the haystack
800+ /// Checks whether the pattern matches at the front of the haystack.
775801 #[ inline]
776802 fn is_prefix_of ( self , haystack : & ' a str ) -> bool {
777803 haystack. as_bytes ( ) . starts_with ( self . as_bytes ( ) )
@@ -788,7 +814,7 @@ impl<'a, 'b> Pattern<'a> for &'b str {
788814 }
789815 }
790816
791- /// Checks whether the pattern matches at the back of the haystack
817+ /// Checks whether the pattern matches at the back of the haystack.
792818 #[ inline]
793819 fn is_suffix_of ( self , haystack : & ' a str ) -> bool {
794820 haystack. as_bytes ( ) . ends_with ( self . as_bytes ( ) )
0 commit comments