What does it mean `T : 'static`?

Viewed 95

What is the proper understanding of the restriction T : 'static ? As I understand it means "anything implementing T should not have a reference / pointer either directly or indirectly". I am asking because I used to think that it means anything implementing T should exist during the whole lifetime of the application, but such interpretation looks wrong for me now.

1 Answers

Your new understanding is correct. T: 'static means T does not contain lifetimes, or may live during the entire program, but doesn't have to.

See also Common Lifetime Misconceptions: if T: 'static then T must be valid for the entire program.

For example, String: 'static holds, but you can drop a String whenever you want and you cannot access it anymore. It is just that if I have a String and I don't drop it, I can hold it forever without have to worry it will be invalidated behind my back because, say, the underlying storage was freed.

Related