3 ms·
Not sure why this is being downvoted. The GP commenter is mistaken, the following line is completely valid Rust: const USAGE: &str = "usage: blah blah"; C
by kibwen 9y ago
Not sure why this is being downvoted. The GP commenter is mistaken, the following line is completely valid Rust:
const USAGE: &str = "usage: blah blah";
Compare it to the equivalent in C:
const char *USAGE = "usage: blah blah";
- CalChris 9y agoAnd while you are at it, compare that to: #define USAGE "usage: blah blah"
- dtolnay 9y agoThe equivalent C needs a second const -- your first one refers to the data behind the string but not the string pointer, and is more like Rust's `let usage: &str`. const char * const USAGE = "usage: blah blah";
- crzwdjk 9y agoOr rather `let mut usage: &str`. Rust actually is kind of similar to C here in that the pointer and pointee can be separately const or mutable. But in Rust "const" is the default and mut needing to be explicitly declared, whereas with C it's the other way around.