Skip to content

Instantly share code, notes, and snippets.

@mitchmindtree
Created February 9, 2015 07:16
Show Gist options
  • Save mitchmindtree/98d1322e7b73ebad6783 to your computer and use it in GitHub Desktop.
Save mitchmindtree/98d1322e7b73ebad6783 to your computer and use it in GitHub Desktop.
Strange associated types behaviour
use std::num::Float;
trait Foo {
type A: Float;
// Why is it that this doesn't work...
fn sub_a(&self, a: <Self as Foo>::A, b: <Self as Foo>::A) -> <Self as Foo>::A {
a - b
}
// ... and this does.
fn sub_b(&self, a: <Self as Foo>::A, b: <Self as Foo>::A) -> <Self as Foo>::A {
fn sub<T: Float>(a: T, b: T) -> T { a - b }
sub(a, b)
}
}
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment