These are chat archives for rust-lang/rust

21st
Mar 2017
Stan Kondrat
@stan-kondrat
Mar 21 2017 20:10
Hello, for learning Rust lang I writing Promise (promise-rs) library and looks like I have impediment in understanding how static lifetime works .
Can static lifetime in structs and closures be reason for memory leaks?
Jacob Kiesel
@Xaeroxe
Mar 21 2017 20:48
Not under normal circumstances no. A static lifetime is the largest possible lifetime, it guarantees the reference will be valid for the entire duration of the process.
Ingvar Stepanyan
@RReverser
Mar 21 2017 21:37
To be more precise, static lifetime denotes exactly lifetime of static items (that is, those that are available at compile-time and are inlined into binary as constants)

For let x: String = ... what is the difference between &x and x.as_str()? Do I miss something or weren't these variants equivalent at some point of time?

@Crazy-Owl they should be exactly same AFAIK; one is just implementation of special Borrow trait which tells that &x can convert &String to &str, and another is explicit method on String

Ingvar Stepanyan
@RReverser
Mar 21 2017 21:43
as_str just implicitly calls the former