Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Mul<A> {
- f: Box<dyn Fn(A) -> i32>
- }
- impl<A> Mul<A> {
- fn call(&self, a: A) {
- println!("Result: {:?}", (self.f)(a));
- }
- }
- fn create<A>(f: Box<dyn Fn(A) -> i32>) -> Mul<A> {
- Mul { f }
- }
- fn main() {
- let double_mul = create(Box::new(|x: &i32| *x * 2));
- let arg = 333;
- double_mul.call(&arg);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement