Steven Blenkinsop wrote:
Can you clarify the syntax for function types with lifetime parameters? I saw this in the meeting transcript:

    &fn<'a>(f: &fn(&'a T))
    &fn(f: &fn<'a>(&'a T))


I think I've filled in blanks that were left correctly. I'm guessing the that the first case forces the lifetime 'a to be known when you call the function, and the second case allows the lifetime 'a to be determined inside the body of the function as needed on each call to f. I'm pretty sure that the <'a> in both cases is new syntax, since I don't think you can put type parameters on function values. Is this correct?

This is exactly correct and yes <'a> would be new syntax.

The first form (with 'a bound on the outer fn) is pretty close to useless, I imagine, because the outer fn has no way to know what the lifetime 'a is and moreover it has no pointers with that lifetime. This implies that it could invoke its argument `f` with pointers whose lifetime is 'static. So the first function is, for all intents and purposes, equivalent to

&fn(f: &fn(&'static T))

I am not 100% sure if this pattern arises in other cases where it might be more important, but I can't imagine what such a case would be.


Niko
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to