After reading the recent discussions about lifetime notation, I was wondering why lifetimes need their own names. Lifetimes refer to variables that already have names. For example, given this fn from the borrowed pointers tutorial:

    fn select<T>(shape: &Shape, threshold: float,
                 a: &r/T, b: &r/T) -> &r/T {
        if compute_area(shape) > threshold {a} else {b}
    }

What does lifetime `r` actually need a name? The return type is referring to the lifetime of the `a` and `b` parameters. Those parameters already have names. Is it possible to declare a type that references a lifetime name that is not in scope? Could the return type refer to those names (`a` or `b`)? For example:

    fn select<T>(shape: &Shape, threshold: float,
                 a: &T, b: &T) -> &a/T {
        if compute_area(shape) > threshold {a} else {b}
    }


Regarding syntax, since the lifetime is annotating a type, would a lifetime suffix be feasible? For example, &T is a "pointer to T" and &T'lt could be a "pointer to type T with a lifetime of lt"

chris

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to