Skip to content

Instantly share code, notes, and snippets.

@dobkeratops
Last active June 20, 2017 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dobkeratops/a68a600884ad5ac9219966402d814d36 to your computer and use it in GitHub Desktop.
Save dobkeratops/a68a600884ad5ac9219966402d814d36 to your computer and use it in GitHub Desktop.
// This compiles, but didn't need lifetime annotations.
// what does this do differently compared to the version using operators?
pub trait MulRef<B> {
type Output;
fn mul_ref(&self,&B)->Self::Output;
}
pub trait AddRef<B> {
type Output;
fn add_ref(&self,&B)->Self::Output;
}
pub fn madd_r1<A,B,C,P>(a:&A,b:&B,c:&C)->A where
B:MulRef<C,Output=P>,
A:AddRef<P,Output=A>,
{
let p=b.mul_ref(c);
a.add_ref(&p)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment