3 ms·
The article is not about what you think it's about. 1. Turns out that zeroing u8 is a special case so if you allocate 17 GB of your custom structure Rust is go
by gridspy 5y ago
The article is not about what you think it's about.
1. Turns out that zeroing u8 is a special case so if you allocate 17 GB of your custom structure Rust is gonna init that for you.
2. Okay, so you don't understand how RefCell works? The caller to this function should be holding r, not passing it into the function. Of course that will just correctly Panic, so it's not wonderful. But that is the point of RefCell.
Generally more stuff runs fast in Rust than in other languages, but you can always find bad counterexamples in any language.
- celeritascelery 5y ago> 2. Okay, so you don't understand how RefCell works? The caller to this function should be holding r, not passing it into the function. Of course that will just correctly Panic, so it's not wonderful. But that is the point of RefCell. That’s not the interesting part. The point is that rust won’t optimize a lifetime inside a struct the same way it will optimize an actual reference. It can’t assume that the lifetime will be valid for the whole function (as it can with ref). This limits the amount of reordering you can do in the optimizer. The example you were looking at was explaining why that is the case.
- gridspy 5y agoOkay, thanks for clarifying that. Ultimately I'm happy for Rust to only be so smart, of course there are going to be limitations. But you are right, the author was making a clear example and my comment doesn't make sense in that context.
- spoiler 5y agoIsn't this (at least in part) addressed by NLLs[1], or am I misunderstanding? [1]: https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md https://github.com/rust-lang/rfcs/blob/master/text/2094-nll....