@@ -61,7 +61,6 @@ use core::str::pattern::Pattern;
61
61
use core:: str:: pattern:: { Searcher , ReverseSearcher , DoubleEndedSearcher } ;
62
62
use unicode:: str:: { UnicodeStr , Utf16Encoder } ;
63
63
64
- use core:: convert:: AsRef ;
65
64
use vec_deque:: VecDeque ;
66
65
use borrow:: { Borrow , ToOwned } ;
67
66
use string:: String ;
@@ -85,18 +84,18 @@ pub use core::str::pattern;
85
84
Section: Creating a string
86
85
*/
87
86
88
- impl < S : AsRef < str > > SliceConcatExt < str , String > for [ S ] {
87
+ impl < S : Borrow < str > > SliceConcatExt < str , String > for [ S ] {
89
88
fn concat ( & self ) -> String {
90
89
if self . is_empty ( ) {
91
90
return String :: new ( ) ;
92
91
}
93
92
94
93
// `len` calculation may overflow but push_str will check boundaries
95
- let len = self . iter ( ) . map ( |s| s. as_ref ( ) . len ( ) ) . sum ( ) ;
94
+ let len = self . iter ( ) . map ( |s| s. borrow ( ) . len ( ) ) . sum ( ) ;
96
95
let mut result = String :: with_capacity ( len) ;
97
96
98
97
for s in self {
99
- result. push_str ( s. as_ref ( ) )
98
+ result. push_str ( s. borrow ( ) )
100
99
}
101
100
102
101
result
@@ -115,7 +114,7 @@ impl<S: AsRef<str>> SliceConcatExt<str, String> for [S] {
115
114
// this is wrong without the guarantee that `self` is non-empty
116
115
// `len` calculation may overflow but push_str but will check boundaries
117
116
let len = sep. len ( ) * ( self . len ( ) - 1 )
118
- + self . iter ( ) . map ( |s| s. as_ref ( ) . len ( ) ) . sum :: < usize > ( ) ;
117
+ + self . iter ( ) . map ( |s| s. borrow ( ) . len ( ) ) . sum :: < usize > ( ) ;
119
118
let mut result = String :: with_capacity ( len) ;
120
119
let mut first = true ;
121
120
@@ -125,7 +124,7 @@ impl<S: AsRef<str>> SliceConcatExt<str, String> for [S] {
125
124
} else {
126
125
result. push_str ( sep) ;
127
126
}
128
- result. push_str ( s. as_ref ( ) ) ;
127
+ result. push_str ( s. borrow ( ) ) ;
129
128
}
130
129
result
131
130
}
0 commit comments