Why statics exist before main starts, outlive every frame, and are read without copying
Statics are baked into the compiled program, so they exist before main starts. Each &str static is a pointer and a length to text in read-only memory
1static GREETING_GLOBAL: &str = "Hello, universe!";// ← already in the binary23fn main() {4 println!("{}", GREETING);5 println!("{}", GREETING_GLOBAL);67 static GREETING: &str = "Hello, world!";8}Why statics exist before main starts, outlive every frame, and are read without copying
main and last until the process exits&'static str is a pointer and a length into read-only memory&str copies the pointer, never the textconst is inlined wherever it is used and has no fixed address, while a static has exactly one address for the whole programstatic mut needs unsafe, because any thread could be changing it at the same timeT: 'static means the type holds no borrows shorter than 'static, not that the value lives forever$cargorun// waiting for the first println!