Skip to content

Instantly share code, notes, and snippets.

@sophiajt
Last active May 15, 2016 17:09
Show Gist options
  • Save sophiajt/6b188a65a450909d1c6fe927537cee70 to your computer and use it in GitHub Desktop.
Save sophiajt/6b188a65a450909d1c6fe927537cee70 to your computer and use it in GitHub Desktop.
trait FnRegister<A, RetVal, Args> {
fn register(&mut self, name: &str, f: A);
}
impl<A, RetVal, Arg1> FnRegister<A, RetVal, (Arg1,)> for Bob
where A: 'static + Fn(Arg1)->RetVal
{
fn register(self, name: &str, fun: fn(Arg1)->RetVal) {
println!("Fn(T)->U");
}
}
impl<'a, A, RetVal, Arg1> FnRegister<A, RetVal, (&'a Arg1,)> for Bob
where A: 'static + Fn(&Arg1)->RetVal
{
fn register(self, name: &str, fun: fn(&Arg1)->RetVal) {
println!("Fn(&T)->U");
}
}
struct Bob { x: u32 }
impl Bob {
fn bob_val(self) {
println!("bob_val");
}
fn bob_ref(&self) {
println!("bob_ref");
}
}
fn main() {
let mut bob = Bob { x: 1 };
bob.register("bob_val", Bob::bob_val);
bob.register("bob_ref", Bob::bob_ref);
}
/*
error: conflicting implementations of trait `FnRegister<_, _, (&_,)>` for type `Bob`: [--explain E0119]
--> testme.rs:13:1
13 |> impl<'a, A, RetVal, Arg1> FnRegister<A, RetVal, (&'a Arg1,)> for Bob
|> ^
note: conflicting implementation is here:
--> testme.rs:5:1
5 |> impl<A, RetVal, Arg1> FnRegister<A, RetVal, (Arg1,)> for Bob
|> ^
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment