Another case that &mut Option<dyn Trait>
might be useful is to handle the Box<FnOnce>
issue.
fn main() {
let c = ||{};
let b :Box<dyn FnOnce()> = Box::new(c);
b()
}
Today the above results in E0161: cannot move out of box. But we can image to have compiler support for desugaring it to:
fn main() {
let c = ||{};
let b:Box<dyn FnOnce()> = box c;
//this only copies the vtable, and move the destructor from b to the place holder
let _place_holder:&mut Option<dyn FnOnce()> = unbox_to_some(b);
//fn call_once_derived(self: &mut Option<dyn FnOnce()>)
//{ (self.take().unsafe_unwrap())() }
_place_holder.call_once_derived()
}