> Rust 1.45.0 adds the ability to invoke procedural macros in three new places!<p>Rust 1.45 will be the Rocket Release. It unblocks Rocket running on stable as tracked here <a href="https://github.com/SergioBenitez/Rocket/issues/19" rel="nofollow">https://github.com/SergioBenitez/Rocket/issues/19</a><p>This is so excellent, and I love seeing long term, multiyear goals get completed. It isn't just this release, but all the releases in between. The Rust team and community is amazing.
This rather niche fixing of unsafe behaviour is excellent:
<a href="https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#fixing-unsoundness-in-casts" rel="nofollow">https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#fixin...</a><p>I spent a few years as a scientific programmer and this is exactly the sort of thing that just bites you on the behind in C/C++/Fortran: the undefined behaviour can actually manifest as noise in your output, or just really hard to track down, intermittent problems. A big win to get rid of it.
I keep seeing more and more news about Rust, and figure that perhaps it is time that I learn something new.<p>99% of my development work these days is C with the target being Linux/ARM with a small-ish memory model. Think 64 or 128MB of DDR. Does this fit within Rust's world?<p>I've noticed that stripped binary sizes for a simple "Hello, World!" example are significantly larger with Rust. Is this just the way things are and the "cost of protection"? For reference, using rustc version 1.41.0, the stripped binary was 199KiB and the same thing in C (gcc 9.3) was 15KiB.
> array[i] will check to make sure that array has at least i elements.<p>At least i+1 elements, right? Or am I getting caught up by one of the three hardest problems again?
By any chance if anyone is in the Paris area and is interested to teach Rust at university next year during the first semester. Please get in touch :).
I'm building an embedded project that currently runs a python script for automatic brightness. It takes a brightness value from a sensor over I2C, applies a function to get an appropriate LCD brightness value and then sends that to the display driver over a serial port. Would this be an appropriate project to write in Rust to learn the basics of this language?
As someone who hasn't used Rust, I am curious about why Rust has macros.<p>I use C++ at work, which admittedly isn't the language I use most, and macros are used quite a bit in the code base. I find they just make the code harder to read, reason about, debug, and sometimes even write. I don't see them really living up to their claimed value.<p>Is there something different about Rust's macros that make them better?
The post says<p><pre><code> The new API to cast in an unsafe manner is:
let x: f32 = 1.0;
let y: u8 = unsafe { x.to_int_unchecked() };
But as always, you should only use this method as a last resort. Just like with array access, the compiler can often optimize the checks away, making the safe and unsafe versions equivalent when the compiler can prove it.
</code></pre>
I believe for array access you can elide the bounds checking with an assert like<p><pre><code> assert!(len(arr) <= 255)
let mut sum = 0;
for i in 0..255 {
sum += arr[i];//this access doesn't emit bounds checks in the compiled code
}
</code></pre>
I'm guessing it would work like this with casts?<p><pre><code> assert!(x <= 255. && x >= 0);
let y: u8 = x as u8; // no check</code></pre>
> Just like with array access, the compiler can often optimize the checks away, making the safe and unsafe versions equivalent when the compiler can prove it.<p>Can it "often" solve the halting problem as well?<p>The hope that this kind of optimization will happen sounds a bit fanciful for any non-trivial part of a program.