News for hackers. Stuff that matters.
Re:The humble for loop in Rust by GuB-42 on Friday December 13, 2024 @03:07PM (#42411870)
Is there a reason why the loop and map don't result in the exact same code?

It looks like the code does exactly the same thing and something the optimizer could catch. Is is because of potential side effects? If not, maybe there is a ticket to open somewhere, if it isn't done already.

Re:The humble for loop in Rust by skavi on Friday December 13, 2024 @05:20PM (#42412870)
The FromIterator impl for Vec is specialized with unsafe code for these cases.

FromIterator is the trait that the collect method uses.

Specialization isn’t a stable feature in Rust, but is used extensively in the standard library.