3 ms·
I'm confused about the bullet point "IntoIterator for arrays". I thought this was added already in Rust 1.53.0. Did something else happen? See https://blog.rus
by nayuki 5y ago
I'm confused about the bullet point "IntoIterator for arrays". I thought this was added already in Rust 1.53.0. Did something else happen?
See https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html#whats-in-1530-stable https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html#whats...
- davisoneee 5y agoTo follow Steve's comment: > Until Rust 1.53, only references to arrays implement IntoIterator. This means you can iterate over &[1, 2, 3] and &mut [1, 2, 3], but not over [1, 2, 3] directly. ...now, you can also iterate over [1, 2, 3] etc. https://doc.rust-lang.org/edition-guide/rust-2021/IntoIterator-for-arrays.html https://doc.rust-lang.org/edition-guide/rust-2021/IntoIterat...
- steveklabnik 5y agoRight, but the point is that you can do that as of 1.53.0, you didn't have to wait until this release and the edition to do it.
- tialaramex 5y agoYou know all this, but while some obvious things work in 1.53.0 one important thing causes scary warnings because it is shadowed by the back compat hack. "for x in myArray" works fine, just like "for x in myVector" but whereas "myVector.into_iter().foo()" does what you expect, "myArray.into_iter().foo() is actually giving foo an iterator over the references just as it would have in 2017 and now produces a warning about this into the bargain. In Rust 2021 myArray.into_iter() does what a modern Rust programmer expects it to do, provide an iterator over myArray itself. The warning does explain how you can get that iterator in 1.53.0 of course, but you need to write some ugly syntax whereas in Rust 2021 the obvious syntax just does what you expect as if arrays had always been IntoIterator.
- steveklabnik 5y agoThere's an explanation at the bottom of the section; this landed as a hack in previous editions, but works via the normal mechanisms in Rust 2021. "Since this special case for .into_iter() is only required to avoid breaking existing code, it is removed in the new edition, Rust 2021, which will be released later this year." As a user, you're right that there's not really an external-facing change here.