Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. struct Mul<A> {
  2. f: Box<dyn Fn(A) -> i32>
  3. }
  4.  
  5. impl<A> Mul<A> {
  6. fn call(&self, a: A) {
  7. println!("Result: {:?}", (self.f)(a));
  8. }
  9. }
  10.  
  11. fn create<A>(f: Box<dyn Fn(A) -> i32>) -> Mul<A> {
  12. Mul { f }
  13. }
  14.  
  15. fn main() {
  16. let double_mul = create(Box::new(|x: &i32| *x * 2));
  17. let arg = 333;
  18. double_mul.call(&arg);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement