In theory there could be the following implementation:
impl<Input,Output,F> FnMut<Input> for F
where
F: FnOnce(Input) -> Output + Clone
{
extern "rust-call" fn call_mut(&mut self, args: Input) -> Output {
(self.clone())(args)
}
}
impl<Input,Output,F> Fn<Input> for F
where
F: FnOnce(Input) -> Output + Clone
{
extern "rust-call" fn call(&self, args: Input) -> Output {
(self.clone())(args)
}
}
The problem here, is of cause this inevidablely results in conflict implementations. Can specialization solve this problem and then we can put the above in std?
Or you could change the fn names in the initial proposal to include the clone semantics in the name, thereby making that aspect not hidden: fn call_cloned_mut() and fn call_cloned().
I think this is in the same category as the long-desired impl<T:Copy> Clone for T – not something possible right now, with further discussion waiting on the traits refactoring work (chalk, etc).