2 ms·
> Leaking a data structure proves to the compiler that it will stay around indefinitely (i.e: it has a "static" lifetime), for example, which allows you to do t
by hiq 6y ago
> Leaking a data structure proves to the compiler that it will stay around indefinitely (i.e: it has a "static" lifetime), for example, which allows you to do things with it that Rust would normally forbid.
Asking as a Rust neophyte: are you saying that one thus declares a static lifetime without using the static lifetime name (https://doc.rust-lang.org/stable/rust-by-example/scope/lifetime/static_lifetime.html https://doc.rust-lang.org/stable/rust-by-example/scope/lifet...)? In which case would you do one way over the other then?
- steveklabnik 6y agoThe type signature of the leak function is pub fn leak<'a>(b: Box<T>) -> &'a mut T where T: 'a, If T is owned, or only contains ‘static references itself, then ‘a must also be ‘static. Does that help at all?