3 ms·
This is really misleading and I wish people would stop but for some reason everyone is like "Rust is actually easy! You already have to think about borrowing an
by IshKebab 7y ago
This is really misleading and I wish people would stop but for some reason everyone is like "Rust is actually easy! You already have to think about borrowing and lifetimes in C/C++ - Rust just makes it explicit.".
I love Rust, but that is nonsense. First of all it's a reasonable complicated language even without lifetimes and the borrow checker, but let's ignore that. My issue with this sentiment is that it ignores the fact that the borrow checker isn't smart enough to prove that loads of perfectly valid programs are valid.
A simple example: `a[0].foo = a[1].foo;`. Perfectly valid. No memory errors. But Rust isn't smart enough to know, and so it really does make things harder than in C/C++.
This isn't a criticism of Rust at all. I think it is a worthwhile tradeoff to get memory safety. I just wish people would stop pretending that it isn't a tradeoff at all!
- lonelappde 7y agoHow do you copy data from one array of structs to another in rust? Also, if foo is a non-shared pointer that copy doesn't seem safe.
- steveklabnik 7y ago> How do you copy data from one array of structs to another in rust? Depends on exactly what you mean; if you're trying to say, replace one part of an array with another, you would use copy_from_slice https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=e29e9522d81d3cbe3960e842de758d4b https://play.rust-lang.org/?version=stable&mode=debug&editio... (or clone_from_slice if your struct isn't Copy) Also, your parent is just plain incorrect, Rust does let you do that https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b9d788265b3881a282e46d201dd0b2e5 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- IshKebab 7y agoSorry, you are correct. I was thinking of situations like this: fn assign(a: &mut Bar, b: &Bar) { a.foo = b.foo; } assign(&mut a[0], &a[1]); Bit contrived - next time Rust stops me doing something simple I will note it down! Again to be clear, I'm not saying that there's anything wrong with Rust here.
- steveklabnik 7y agoAh yeah, you can split_at_mut here, but you're right that that's an actual error. My bad!