2 #![allow(unused_imports)]
3 // A model for how the `Fn` traits could work. You can implement at
4 // most one of `Go`, `GoMut`, or `GoOnce`, and then the others follow
7 // aux-build:go_trait.rs
11 use go_trait::{Go, GoMut, GoOnce, go, go_mut, go_once};
16 struct SomeGoableThing {
17 counter: Rc<Cell<isize>>
20 impl Go for SomeGoableThing {
21 fn go(&self, arg: isize) {
22 self.counter.set(self.counter.get() + arg);
26 struct SomeGoOnceableThing {
27 counter: Rc<Cell<isize>>
30 impl GoOnce for SomeGoOnceableThing {
31 fn go_once(self, arg: isize) {
32 self.counter.set(self.counter.get() + arg);
37 let counter = Rc::new(Cell::new(0));
38 let mut x = SomeGoableThing { counter: counter.clone() };
41 assert_eq!(counter.get(), 10);
44 assert_eq!(counter.get(), 110);
47 assert_eq!(counter.get(), 1_110);
49 let x = SomeGoOnceableThing { counter: counter.clone() };
52 assert_eq!(counter.get(), 11_110);