Open
Description
#![feature(unboxed_closures)]
#![feature(fn_traits)]
#![allow(unused)]
use std::rc::Rc;
struct MyFn {
cb: Rc<dyn Fn()>,
}
impl FnOnce<()> for MyFn {
type Output = ();
extern "rust-call" fn call_once(self, _args: ()) -> Self::Output {
(self.cb)()
}
}
impl FnMut<()> for MyFn {
extern "rust-call" fn call_mut(&mut self, _args: ()) {
(self.cb)()
}
}
// // Uncomment this to see the conflict From<F> implementation makes
// impl Fn<()> for MyFn {
// extern "rust-call" fn call(&self, _args: ()) {
// (self.cb)()
// }
// }
// When MyFn implements Fn<()>
// From<F> will also
// impl From<MyFn> for MyFn {}
impl<F> From<F> for MyFn
where
F: Fn() + 'static,
{
fn from(f: F) -> Self {
MyFn {
cb: Rc::new(f),
}
}
}