|
15 | 15 | universal_impl_trait,
|
16 | 16 | fn_traits,
|
17 | 17 | step_trait,
|
18 |
| - unboxed_closures |
| 18 | + unboxed_closures, |
| 19 | + copy_closures, |
| 20 | + clone_closures |
19 | 21 | )]
|
20 | 22 |
|
21 | 23 | //! Derived from: <https://raw.githubusercontent.com/quickfur/dcal/master/dcal.d>.
|
@@ -234,54 +236,22 @@ impl Weekday {
|
234 | 236 | }
|
235 | 237 | }
|
236 | 238 |
|
237 |
| -/// Wrapper for zero-sized closures. |
238 |
| -// HACK(eddyb) Only needed because closures can't implement Copy. |
239 |
| -struct Fn0<F>(std::marker::PhantomData<F>); |
240 |
| - |
241 |
| -impl<F> Copy for Fn0<F> {} |
242 |
| -impl<F> Clone for Fn0<F> { |
243 |
| - fn clone(&self) -> Self { *self } |
244 |
| -} |
245 |
| - |
246 |
| -impl<F: FnOnce<A>, A> FnOnce<A> for Fn0<F> { |
247 |
| - type Output = F::Output; |
248 |
| - |
249 |
| - extern "rust-call" fn call_once(self, args: A) -> Self::Output { |
250 |
| - let f = unsafe { std::mem::uninitialized::<F>() }; |
251 |
| - f.call_once(args) |
252 |
| - } |
253 |
| -} |
254 |
| - |
255 |
| -impl<F: FnMut<A>, A> FnMut<A> for Fn0<F> { |
256 |
| - extern "rust-call" fn call_mut(&mut self, args: A) -> Self::Output { |
257 |
| - let mut f = unsafe { std::mem::uninitialized::<F>() }; |
258 |
| - f.call_mut(args) |
259 |
| - } |
260 |
| -} |
261 |
| - |
262 |
| -trait AsFn0<A>: Sized { |
263 |
| - fn copyable(self) -> Fn0<Self>; |
264 |
| -} |
265 |
| - |
266 |
| -impl<F: FnMut<A>, A> AsFn0<A> for F { |
267 |
| - fn copyable(self) -> Fn0<Self> { |
268 |
| - assert_eq!(std::mem::size_of::<F>(), 0); |
269 |
| - Fn0(std::marker::PhantomData) |
270 |
| - } |
271 |
| -} |
272 |
| - |
273 | 239 | /// GroupBy implementation.
|
274 | 240 | struct GroupBy<It: Iterator, F> {
|
275 | 241 | it: std::iter::Peekable<It>,
|
276 | 242 | f: F,
|
277 | 243 | }
|
278 | 244 |
|
279 | 245 | impl<It, F> Clone for GroupBy<It, F>
|
280 |
| -where It: Iterator + Clone, It::Item: Clone, F: Clone { |
281 |
| - fn clone(&self) -> GroupBy<It, F> { |
| 246 | +where |
| 247 | + It: Iterator + Clone, |
| 248 | + It::Item: Clone, |
| 249 | + F: Clone, |
| 250 | +{ |
| 251 | + fn clone(&self) -> Self { |
282 | 252 | GroupBy {
|
283 | 253 | it: self.it.clone(),
|
284 |
| - f: self.f.clone() |
| 254 | + f: self.f.clone(), |
285 | 255 | }
|
286 | 256 | }
|
287 | 257 | }
|
@@ -331,14 +301,11 @@ impl<It: Iterator, F: FnMut(&It::Item) -> G, G: Eq> Iterator for InGroup<It, F,
|
331 | 301 | }
|
332 | 302 |
|
333 | 303 | trait IteratorExt: Iterator + Sized {
|
334 |
| - fn group_by<G, F>(self, f: F) -> GroupBy<Self, Fn0<F>> |
335 |
| - where F: FnMut(&Self::Item) -> G, |
| 304 | + fn group_by<G, F>(self, f: F) -> GroupBy<Self, F> |
| 305 | + where F: Clone + FnMut(&Self::Item) -> G, |
336 | 306 | G: Eq
|
337 | 307 | {
|
338 |
| - GroupBy { |
339 |
| - it: self.peekable(), |
340 |
| - f: f.copyable(), |
341 |
| - } |
| 308 | + GroupBy { it: self.peekable(), f } |
342 | 309 | }
|
343 | 310 |
|
344 | 311 | fn join(mut self, sep: &str) -> String
|
@@ -382,7 +349,7 @@ fn test_spaces() {
|
382 | 349 | fn dates_in_year(year: i32) -> impl Iterator<Item=NaiveDate>+Clone {
|
383 | 350 | InGroup {
|
384 | 351 | it: NaiveDate::from_ymd(year, 1, 1)..,
|
385 |
| - f: (|d: &NaiveDate| d.year()).copyable(), |
| 352 | + f: |d: &NaiveDate| d.year(), |
386 | 353 | g: year
|
387 | 354 | }
|
388 | 355 | }
|
|
0 commit comments