File tree 3 files changed +27
-15
lines changed
3 files changed +27
-15
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ use core::mem;
25
25
use core:: ops:: { self , Deref , Add , Index } ;
26
26
use core:: ptr;
27
27
use core:: slice;
28
+ use core:: str:: Pattern ;
28
29
use unicode:: str as unicode_str;
29
30
use unicode:: str:: Utf16Item ;
30
31
@@ -765,6 +766,25 @@ impl<'a> Extend<&'a str> for String {
765
766
}
766
767
}
767
768
769
+ /// A convenience impl that delegates to the impl for `&str`
770
+ impl < ' a , ' b > Pattern < ' a > for & ' b String {
771
+ type Searcher = <& ' b str as Pattern < ' a > >:: Searcher ;
772
+
773
+ fn into_searcher ( self , haystack : & ' a str ) -> <& ' b str as Pattern < ' a > >:: Searcher {
774
+ self [ ..] . into_searcher ( haystack)
775
+ }
776
+
777
+ #[ inline]
778
+ fn is_contained_in ( self , haystack : & ' a str ) -> bool {
779
+ self [ ..] . is_contained_in ( haystack)
780
+ }
781
+
782
+ #[ inline]
783
+ fn is_prefix_of ( self , haystack : & ' a str ) -> bool {
784
+ self [ ..] . is_prefix_of ( haystack)
785
+ }
786
+ }
787
+
768
788
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
769
789
impl PartialEq for String {
770
790
#[ inline]
Original file line number Diff line number Diff line change @@ -474,22 +474,16 @@ impl<'a, 'b> Pattern<'a> for &'b [char] {
474
474
s, CharEqPattern ( s) ) ;
475
475
}
476
476
477
+ /// A convenience impl that delegates to the impl for `&str`
478
+ impl < ' a , ' b > Pattern < ' a > for & ' b & ' b str {
479
+ type Searcher = <& ' b str as Pattern < ' a > >:: Searcher ;
480
+ associated_items ! ( <& ' b str as Pattern <' a>>:: Searcher ,
481
+ s, ( * s) ) ;
482
+ }
483
+
477
484
/// Searches for chars that match the given predicate
478
485
impl < ' a , F > Pattern < ' a > for F where F : FnMut ( char ) -> bool {
479
486
type Searcher = <CharEqPattern < Self > as Pattern < ' a > >:: Searcher ;
480
487
associated_items ! ( <CharEqPattern <Self > as Pattern <' a>>:: Searcher ,
481
488
s, CharEqPattern ( s) ) ;
482
489
}
483
-
484
- // Deref-forward impl
485
-
486
- use ops:: Deref ;
487
-
488
- /// Delegates to the next deref coercion of `Self` that implements `Pattern`
489
- impl < ' a , ' b , P : ' b + ?Sized , T : Deref < Target = P > + ?Sized > Pattern < ' a > for & ' b T
490
- where & ' b P : Pattern < ' a >
491
- {
492
- type Searcher = <& ' b P as Pattern < ' a > >:: Searcher ;
493
- associated_items ! ( <& ' b P as Pattern <' a>>:: Searcher ,
494
- s, ( & * * s) ) ;
495
- }
Original file line number Diff line number Diff line change @@ -13,9 +13,7 @@ fn test_pattern_deref_forward() {
13
13
let data = "aabcdaa" ;
14
14
assert ! ( data. contains( "bcd" ) ) ;
15
15
assert ! ( data. contains( & "bcd" ) ) ;
16
- assert ! ( data. contains( &&"bcd" ) ) ;
17
16
assert ! ( data. contains( & "bcd" . to_string( ) ) ) ;
18
- assert ! ( data. contains( &&"bcd" . to_string( ) ) ) ;
19
17
}
20
18
21
19
#[ test]
You can’t perform that action at this time.
0 commit comments