On 04/30/2014 04:04 AM, Vladimir Panteleev wrote:

fn map<'r, B>(self, f: |A|: 'r -> B) -> Map<'r, A, B, Self>

Same as points 1 and 3 above (D's version allows specifying multiple
functions).

Not sure what 'r or |A| means in Rust syntax, but I guess this would be
the equivalent D syntax:

auto map(R)(R delegate(T))

|A| -> B is the type of a closure mapping an A to a B. 'r is a lifetime parameter (there is another one in Self):

I.e. that signature is roughly saying: The returned iterator lives at most as long as the closure context of f and the underlying iterator.

This way you can eg. get an iterator over some mutable data structure, map it without allocations using a stack closure, and the type system verifies that the data structure is not changed while the mapped iterator is in use, and that there are no dangling references to stack memory left behind.

Reply via email to