4 ms·
Not parent, but not a rust programmer: > If I write a Rust program which relies on this for a constant, it works fine, because it is constant, but if I try to
by Karellen 4y ago
Not parent, but not a rust programmer:
> If I write a Rust program which relies on this for a constant, it works fine, because it is constant, but if I try to compile it with Rust 1.68 (from earlier this year) it won't work.
How would it not work? If your program compiles and runs with 1.69, then surely that's because it never tries to modify the value. But if your program never tries to modify the value, how would it fail with 1.68?
- estebank 4y agoThe GP is missing a small bit of context: because this construct is now const, it can be used in const contexts, like to initialize a static variable. Doing so didn't work in 1.68, but does now in 1.69.
- phkahler 4y agoBut older code will still work with the new compiler right?
- proto_lambda 4y ago> a Rust program which relies on this for a constant https://godbolt.org/z/ceY3q3eW4 https://godbolt.org/z/ceY3q3eW4
- Karellen 4y agoSorry, I'm not reading 1100 words of privacy policy to get a chance to read whatever that is.
- addaon 4y agoI recommend just reading or closing the privacy policy -- it's a single screen (on my device) and is quite reasonable. Because "whatever that is" is a godbolt link... and godbolt is one of the absolutely most valuable and greatest tools available for software developers who work in compiled languages. It's definitely worth becoming familiar with.
- Karellen 4y ago> godbolt is one of the absolutely most valuable and greatest tools available for software developers who work in compiled languages. That's a bold claim for a tool that doesn't even have a Wikipedia entry. Edit: or a subreddit.
- Reubachi 4y agoGosh, this website is becoming reddit more and more everyday. YOU don't have a wikipedia entry. Are you also now classified as "whatever that is"? Of course not. I would implore you to open your mind up to resources that aren't popular social media because that's where the real gold/value is in development/engineering.
- Karellen 4y ago> YOU don't have a wikipedia entry. I'm not claiming to be "one of the absolutely most valuable and greatest tools available" though. (Well, maybe the "greatest tool" part ;-) And if someone else claimed that about me, I'd think that either there was something very wrong with them, or that one of my parents had started using alt accounts I didn't know about. Considering some of the software tools that do have dedicated wikipedia pages and subreddits, and that I'd never heard of godbolt before, I don't think it's out of line to be skeptical of such a hyperbolic claim.
- dannymi 4y 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.