The following example:
struct A<'a, T>(&'a T);
impl<'a, T> A<'a, T>
where T: PartialOrd {
fn lt(x: &T, a: &T) -> bool { x < a }
fn f(x: &T) -> bool { Self::lt(x, x) }
}
does not compile. It looks like using Self::lt
induces a dependency on the lifetime of A
. If I use an “external” function:
fn lt<T: PartialOrd>(x: &T, a: &T) -> bool { x < a }
and define f
as
fn f(x: &T) -> bool { lt(x, x) }
it works. Why is there a different treatment for associated functions? (I would prefer to use these as they better point to the fact that lt
will only be used locally.)
Thanks for your help.