3 ms·
Ah, I get your question now, I thought you were talking about const functions. Well, const values in Rust are funny things, they're not linked into the executab
by codeflo 5y ago
Ah, I get your question now, I thought you were talking about const functions. Well, const values in Rust are funny things, they're not linked into the executable, they don't have an address or a lifetime. That confused me too for a while. They're purely a shortcut for a value expression, not that different from a #define in C.
Statics, in contrast, have a storage location and a static lifetime.
Compare:
const CONST_STRING: String = String::new();
static STATIC_STRING: String = String::new();
fn main() {
let x: String = CONST_STRING; // fine
let y: String = STATIC_STRING; // error: cannot move out of static item
}
- brundolf 5y agoOh. I think I didn't realize both existed; I'd only used statics before (and knew about const functions), but didn't know about const expressions.