Replies: 1 comment
-
Intuitively you can think of the
Not really, they can last less than
If the lifetime |
Beta Was this translation helpful? Give feedback.
-
Intuitively you can think of the
Not really, they can last less than
If the lifetime |
Beta Was this translation helpful? Give feedback.
-
A few months ago, I started looking at
smol
's internals to get an idea of "how does one write an async runtime that's understandable by a single person". I've circled around back to this, and remembered where I left off.The
Executor
struct contains anUnsafeCell
to make theExecutor
struct
invariant inState
"lifetime"a
. I'm still a bit shaky on what this means, but AIUI, this means "any types that contaning theExecutor
lifetime'a
must last exactly as long as'a
and no more:Why is this invariance required, and what safety guarantees/assumptions break if the invariance is removed?
I found the a playground snippet I wrote a few months ago as an MCVE of the difference between having the lifetime invariant vs not: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7b7b7c97c6bef5b1d698e2f1d9fbbbd7
This snippet compiles if the lifetime is covariant, and fails to compile if its invariant. So there is a difference. But I was unable to figure out how my MCVE relates to the reasons
smol
uses an invariant lifetime.Beta Was this translation helpful? Give feedback.
All reactions