2 ms·
Idiomatic Rust here would use something like this, not that in this case it makes them performance identical, but it is more representative of real Rust code, a
by steveklabnik 5y ago
Idiomatic Rust here would use something like this, not that in this case it makes them performance identical, but it is more representative of real Rust code, and is slightly smaller https://rust.godbolt.org/z/brh6heEKE https://rust.godbolt.org/z/brh6heEKE
EDIT: lol don’t write code five minuets after waking, the reply to this has far better code
(EDIT: incidentally, I was also curious about a non-extern function, but the compiler is seeing through all of my attempts to call a native Rust function with an opaque body here...)
That being said this code will also be a no-op instead of... something worse, if the vector is empty, so, they're not directly comparable, but they weren't really in the first place, as you mention, so...
- School-Cotton 5y agoWhy not for i in &v[1..num] instead of all the iter take skip stuff?
- steveklabnik 5y agoBecause I wrote this comment shortly after waking up and made a mistake. That code is far far better. Thank you.