Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #![feature(fn_traits, unboxed_closures)]
  2. #[allow(non_camel_case_types)]
  3.  
  4. struct get_max;
  5. fn get_max_fn_body<T: PartialOrd>(a: T, b: T) -> T {
  6. if a > b { a } else { b }
  7. }
  8.  
  9. impl FnOnce<(i32, i32)> for get_max {
  10. type Output = i32;
  11. #[inline(always)]
  12. extern "rust-call" fn call_once(self, args: (i32, i32)) -> Self::Output {
  13. get_max_fn_body.call_once(args)
  14. }
  15. }
  16.  
  17. impl FnMut<(i32, i32)> for get_max {
  18. #[inline(always)]
  19. extern "rust-call" fn call_mut(&mut self, args: (i32, i32)) -> Self::Output {
  20. get_max_fn_body.call_once(args)
  21. }
  22. }
  23.  
  24.  
  25. fn main() {
  26. let x = get_max.call_mut(1,2);
  27. println!("x: {}", x);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement