@@ -451,7 +451,13 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
451
451
452
452
impl < ' a > DoubleEndedSearcher < ' a > for CharSearcher < ' a > { }
453
453
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
+ /// ```
455
461
impl < ' a > Pattern < ' a > for char {
456
462
type Searcher = CharSearcher < ' a > ;
457
463
@@ -696,7 +702,14 @@ unsafe impl<'a, 'b> ReverseSearcher<'a> for CharSliceSearcher<'a, 'b> {
696
702
697
703
impl < ' a , ' b > DoubleEndedSearcher < ' a > for CharSliceSearcher < ' a , ' b > { }
698
704
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
+ /// ```
700
713
impl < ' a , ' b > Pattern < ' a > for & ' b [ char ] {
701
714
pattern_methods ! ( CharSliceSearcher <' a, ' b>, MultiCharEqPattern , CharSliceSearcher ) ;
702
715
}
@@ -738,7 +751,14 @@ where
738
751
739
752
impl < ' a , F > DoubleEndedSearcher < ' a > for CharPredicateSearcher < ' a , F > where F : FnMut ( char ) -> bool { }
740
753
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
+ /// ```
742
762
impl < ' a , F > Pattern < ' a > for F
743
763
where
744
764
F : FnMut ( char ) -> bool ,
@@ -763,6 +783,12 @@ impl<'a, 'b, 'c> Pattern<'a> for &'c &'b str {
763
783
///
764
784
/// Will handle the pattern `""` as returning empty matches at each character
765
785
/// boundary.
786
+ ///
787
+ /// # Examples
788
+ ///
789
+ /// ```
790
+ /// assert_eq!("Hello world".find("world"), Some(6));
791
+ /// ```
766
792
impl < ' a , ' b > Pattern < ' a > for & ' b str {
767
793
type Searcher = StrSearcher < ' a , ' b > ;
768
794
@@ -771,7 +797,7 @@ impl<'a, 'b> Pattern<'a> for &'b str {
771
797
StrSearcher :: new ( haystack, self )
772
798
}
773
799
774
- /// Checks whether the pattern matches at the front of the haystack
800
+ /// Checks whether the pattern matches at the front of the haystack.
775
801
#[ inline]
776
802
fn is_prefix_of ( self , haystack : & ' a str ) -> bool {
777
803
haystack. as_bytes ( ) . starts_with ( self . as_bytes ( ) )
@@ -788,7 +814,7 @@ impl<'a, 'b> Pattern<'a> for &'b str {
788
814
}
789
815
}
790
816
791
- /// Checks whether the pattern matches at the back of the haystack
817
+ /// Checks whether the pattern matches at the back of the haystack.
792
818
#[ inline]
793
819
fn is_suffix_of ( self , haystack : & ' a str ) -> bool {
794
820
haystack. as_bytes ( ) . ends_with ( self . as_bytes ( ) )
0 commit comments