Skip to content

Instantly share code, notes, and snippets.

Created September 27, 2016 20:48
Show Gist options
  • Save anonymous/250304e126a97977db857b2833dc5b85 to your computer and use it in GitHub Desktop.
Save anonymous/250304e126a97977db857b2833dc5b85 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
#![feature(unboxed_closures)]
#![feature(fn_traits)]
#[derive(Clone)]
struct Foo (i32);
type Bar = i32;
impl Foo {
fn go(&self, _: &i32) { }
}
fn _ice() {
let a = vec![].into_iter();
let _ = a.map(Foo(1).clone());
}
impl FnOnce<(Bar,)> for Foo {
type Output = ();
extern "rust-call" fn call_once(self, (args,): (Bar,)) -> Self::Output {
self.go(&args)
}
}
impl FnMut<(Bar,)> for Foo {
extern "rust-call" fn call_mut(&mut self, (args,): (Bar,)) -> Self::Output {
self.go(&args)
}
}
impl FnOnce<Bar> for Foo {
type Output = ();
extern "rust-call" fn call_once(self, args: Bar) -> Self::Output {
self.go(&args)
}
}
impl FnMut<Bar> for Foo {
extern "rust-call" fn call_mut(&mut self, args: Bar) -> Self::Output {
self.go(&args)
}
}
fn main() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment