|
|
|
|
|
by dannymi
1146 days ago
|
|
`const` in Rust is for compile-time constants. In this case, the fn `std::net::SocketAddr::new` was made a const fn recently--but was a regular fn before. >that's because it never tries to modify the value That's something different. If you want variables that are read-only, you don't need any extra keyword. It's the normal case: let x = 5; If you want a mutable variable, you add a `mut` keyword. let mut x = 5; But if you want a compile-time constant, you use `const` instead. const x: u32 = 5; The latter will be evaluated by the compiler at compile time (so interpreted) and substituted BEFORE the user runs the program. This is new-ish stuff and is slowly worming its way into the standard library. |
|