3 ms·
why do we need the lifetime after the function name? i.e. `tokenize<'a>`
by noncoml 6y ago
why do we need the lifetime after the function name? i.e. `tokenize<'a>`
- dpbriggs 6y agoTo make the function generic over some lifetime 'a, similar to how generic functions can be generic over some type T (e.g. foobar<T>). This is usually not necessary to write as it is elided in common use cases.
- noncoml 6y agothanks! I think what was confusing me was that in some examples i see it omitted and in some not. Now it's clear.
- brundolf 6y agoYou can think of it like a generic type parameter. The <'a> is essentially saying "for some lifetime 'a...", and then we refer to that lifetime elsewhere to bind those usages together
- noncoml 6y agoThanks!