The lifetime of temporaries in Rust is a complicated but often ignored topic.
In simple cases, Rust keeps temporaries around for exactly long enough,
such that we don’t have to think about them.
However, there are plenty of cases were we might not get exactly what we want, right away.
In this post, we (re)discover the rules for the lifetime of temporaries,
go over a few use cases for temporary lifetime extension,
and explore a new language idea, super let, to give us more control.
The idea is that these rules just do what you’d expect the language to do in those situations. The additional advantage of Rust is that if you’re wrong, the consequences are just a compilation error, not a crashing program.
The idea is that these rules just do what you’d expect the language to do in those situations. The additional advantage of Rust is that if you’re wrong, the consequences are just a compilation error, not a crashing program.