I'm trying to define a Trait that will be used as a builder. It needs a new method that return Self. For other reasons the trait must have a lifetime parameter. Is this context I unable to implement some default methods (error: a
does not live long enough on g method). I've created a minimal example to show the problem. Changing the definition 'trait Y' for 'impl X' make the code works.
Is this forum the right place to ask this kind of question?
trait Y<'a>: Sized {
//impl<'a> X<'a> {
fn new() -> Self;
//fn new() -> Self {
// X{a: &v}
//}
fn f(&'a self) {
}
fn g() where Self: 'a {
let a = Self::new();
a.f();
}
}
struct X<'a> {
a: &'a i32
}
static v: i32 = 10;
fn main() {}