Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Foo {
- add: u32,
- }
- impl Foo {
- fn make_work<M, W>(&self, make_work: M) -> impl Fn(u32) -> u32 + 'static
- where
- M: FnOnce() -> W,
- W: Fn(u32) -> u32 + 'static,
- {
- let work = make_work();
- let add = self.add;
- move |item| work(item) + add
- }
- }
- fn main() {
- #[derive(Clone)]
- struct MoveOnly(u32);
- let (work, _moved_out) = {
- let add = MoveOnly(5);
- let foo = Foo { add: 10 };
- let work = {
- let add = add.clone();
- foo.make_work(move || {
- move |item| add.0 + item
- })
- };
- (work, add)
- };
- println!("{}", work(100));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement