Rust tips is a user on octodon.social. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.
Rust tips @rust

Iteration with `.iter()` gives references. If you want the elements by value, then you need to dereference or clone them, or use `.into_iter()` instead.

vec.iter().map(|x| /* x is a reference (a pointer) */)
vec.iter().map(|&x| /* x is a value */)
vec.iter().cloned().map(|x| /* x is a value */)

BTW: in closure arguments `&` may seem backwards, because that's a pattern, not a type. The syntax for args is |pattern:type|.

See how it works with `for … in`: is.gd/qo9fVj

· Web · 1 · 2

@rust The more time I spend apart from , the more I wished I used it. Then I inevitably try writing it and remember that even simply copying things requires jumping through hoops. I really want to like it, and maybe eventually I'll spend enough time with it and see the light, but until then, back to .
octodon.social/media/SPSm-pG6c