On 02/05/2013 04:49 AM, Chris Peterson wrote:
> 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:
This is not always true. Consider a function that takes a function as
parameter:
struct Foo { f: int }
fn takes_foo(v : </Foo) -> </int {
&v.f
}
fn foobar(v: </Foo, f: fn(</Foo) -> </int) -> </int{
f(v)
}
fn main() {
let a = Foo {f: 1};
let f = foobar(&a, takes_foo);
io::println(fmt!("%?", f));
}
In this example, the type of the function `f` passed to `foobar` (which
is `fn(</Foo) -> </int`) must have a lifetime annotation to compile
but has no variable name.
> 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"
I don't know :/
--
Samuel de Framond
P: +86 135 8556 8964
M: [email protected]
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev