Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #![feature(box_syntax)]
  2. #![feature(trait_alias)]
  3. #![feature(unboxed_closures)]
  4.  
  5. fn c<T: FnMutClone<()>>(x: T) {}
  6.  
  7. trait FnClone<Args>: Fn<Args> {
  8. fn clone_fn(&self) -> Box<dyn FnClone<Args, Output = Self::Output>>;
  9. }
  10. impl<Args, T: Fn<Args> + Clone + 'static> FnClone<Args> for T {
  11. fn clone_fn(&self) -> Box<dyn FnClone<Args, Output = Self::Output>> { Box::new(self.clone()) }
  12. }
  13.  
  14. trait FnMutClone<Args>: FnMut<Args> {
  15. fn clone_fn(&self) -> Box<dyn FnMutClone<Args, Output = Self::Output>>;
  16. }
  17. impl<Args, T: FnMut<Args> + Clone + 'static> FnMutClone<Args> for T {
  18. fn clone_fn(&self) -> Box<dyn FnMutClone<Args, Output = Self::Output>> { Box::new(self.clone()) }
  19. }
  20.  
  21. fn a() -> Box<dyn FnMutClone() -> ()> {
  22. let a = 1;
  23. box move || { a += 1; }
  24. }
  25.  
  26. fn main() {
  27. c(a())
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement