Skip to content

Comment on Common Rust Lifetime Misconceptions (2020)parent

Comments

Could you elaborate? I find this unintuitive.

Since static lifetimes last for the entirety of the program, it can sub in for any other lifetime (as it is guaranteed to exist until the end of the other lifetime)

I am not familiar with the formal type theory, but this one is intuitive if you view it this way:

1. When A is a subtype of B, it means A can be used as B (a Teacher can be used by any function that accepts a Human).

2. static lifetime lives longer any other lifetimes, so it can be used as other lifetimes.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.