3 ms·
But how would you distinguish between struct A<'a, 'b>(&'a u8, &'b u8); and struct B<'a>(&'a u8, &'a u8); without lifetime annotations?
by giornogiovanna 7y ago
But how would you distinguish between
struct A<'a, 'b>(&'a u8, &'b u8);
and
struct B<'a>(&'a u8, &'a u8);
without lifetime annotations?
- sanxiyn 7y agoYou can always assume the former(all lifetimes are different). It is strictly more general.
- giornogiovanna 7y agoThanks, so lifetimes can definitely be inferred for safe code (although just like type inference, they can lead to leaky abstractions). But aren't lifetime annotations necessary for unsafe code? How could you cast a pointer into a struct into a raw pointer and back, while preserving the lifetime, without them?
- nudq 7y agoWe'd start by making sure these lifetimes need distinguishing, i.e. that they aren't actually equivalent.