How to return closure that borrows &mut self


#1

I have a type Process

type Process = ?;

I want to implement Loadable

pub trait Loadable {
    fn load(&mut self) -> Process;
}

on Component

pub struct Component {
    loaded: bool,
}

like that:

impl Loadable for Component {
    fn load(&mut self) -> Process {
        || {
            self.loaded = true;
        }
    }
}

I want to make concurrent loading with many components those loaded by thread pool.
How could I do that?


#2

I am not sure I have fully understood all the details of what you are trying to do, but something like:

type Process = Box<FnMut(a : Args) -> Result>;

With appropriate argument and return types. After returning you will want to unbox it so you would do something like:

let mut proc = &mut *load();

#3

I already changed my understanding. I am reworked system I want. I will show what I got then.