@@ -176,65 +176,36 @@ where
176176 }
177177}
178178
179- /// Collects characters from a parallel iterator into a string.
180- impl FromParallelIterator < char > for String {
181- fn from_par_iter < I > ( par_iter : I ) -> Self
182- where
183- I : IntoParallelIterator < Item = char > ,
184- {
185- collect_extended ( par_iter)
186- }
187- }
179+ macro_rules! collect_string {
180+ ( $desc: literal, $item: ty $( , $a: lifetime) ?) => {
181+ #[ doc = concat!( "Collects " , $desc, " from a parallel iterator into a string." ) ]
182+ impl $( <$a>) ? FromParallelIterator <$item> for String {
183+ fn from_par_iter<I >( par_iter: I ) -> Self
184+ where
185+ I : IntoParallelIterator <Item = $item>,
186+ {
187+ collect_extended( par_iter)
188+ }
189+ }
188190
189- /// Collects characters from a parallel iterator into a string.
190- impl < ' a > FromParallelIterator < & ' a char > for String {
191- fn from_par_iter < I > ( par_iter : I ) -> Self
192- where
193- I : IntoParallelIterator < Item = & ' a char > ,
194- {
195- collect_extended ( par_iter)
191+ #[ doc = concat!( "Collects " , $desc, " from a parallel iterator into a boxed string." ) ]
192+ impl $( <$a>) ? FromParallelIterator <$item> for Box <str > {
193+ fn from_par_iter<I >( par_iter: I ) -> Self
194+ where
195+ I : IntoParallelIterator <Item = $item>,
196+ {
197+ String :: from_par_iter( par_iter) . into_boxed_str( )
198+ }
199+ }
196200 }
197201}
198202
199- /// Collects string slices from a parallel iterator into a string.
200- impl < ' a > FromParallelIterator < & ' a str > for String {
201- fn from_par_iter < I > ( par_iter : I ) -> Self
202- where
203- I : IntoParallelIterator < Item = & ' a str > ,
204- {
205- collect_extended ( par_iter)
206- }
207- }
208-
209- /// Collects strings from a parallel iterator into one large string.
210- impl FromParallelIterator < String > for String {
211- fn from_par_iter < I > ( par_iter : I ) -> Self
212- where
213- I : IntoParallelIterator < Item = String > ,
214- {
215- collect_extended ( par_iter)
216- }
217- }
218-
219- /// Collects boxed strings from a parallel iterator into one large string.
220- impl FromParallelIterator < Box < str > > for String {
221- fn from_par_iter < I > ( par_iter : I ) -> Self
222- where
223- I : IntoParallelIterator < Item = Box < str > > ,
224- {
225- collect_extended ( par_iter)
226- }
227- }
228-
229- /// Collects string slices from a parallel iterator into a string.
230- impl < ' a > FromParallelIterator < Cow < ' a , str > > for String {
231- fn from_par_iter < I > ( par_iter : I ) -> Self
232- where
233- I : IntoParallelIterator < Item = Cow < ' a , str > > ,
234- {
235- collect_extended ( par_iter)
236- }
237- }
203+ collect_string ! ( "characters" , char ) ;
204+ collect_string ! ( "characters" , & ' a char , ' a) ;
205+ collect_string ! ( "string slices" , & ' a str , ' a) ;
206+ collect_string ! ( "string slices" , Cow <' a, str >, ' a) ;
207+ collect_string ! ( "boxed strings" , Box <str >) ;
208+ collect_string ! ( "strings" , String ) ;
238209
239210/// Collects OS-string slices from a parallel iterator into an OS-string.
240211impl < ' a > FromParallelIterator < & ' a OsStr > for OsString {
0 commit comments