Comment

Comment by wokwokwok

> There is a special lifetime, named 'static, which is valid for the entire program's lifetime.

I've heard this many times before, but as the guide[1] says:

"You might encounter it in two situations... Both are related but subtly different and this is a common source for confusion when learning Rust."

'static means different things for references and trait objects.

ie.

'a: 'static --> reference with lifetime 'a lives forever and can never be dropped.

T: 'static --> Type T has no references in it; it is effectively 'entirely owned' by the owner of an instance of T.

These are totally different things with the same name.

(I believe technically there are actually three; `<T: 'static >` is a type constraint and `T + 'static` is a trait bound, but that both mean the same thing as far as I know)

[1] - https://doc.rust-lang.org/rust-by-example/scope/lifetime/sta...

parent wokwokwok 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton