Doing in again this year (this is not a promise that I'll keep it up 😛), and today is the first day that I feel like I've written somewhat idiomatic Rust, by myself. Very satisfying.


Welp, just posted my first StackOverflow question as a result of my first fight with the borrow checker, as is tradition. Now to wait until it's closed as a duplicate.

But if anyone has any pointers (hehe), would appreciate:

@zseri Yes, that did it! Thank you so much! So to verify my understanding: it now moves `values` into the inner closure, but only the reference inside the outer closure, rather than the value outside of it, and that's why it doesn't need to copy the value?

@zseri That all makes sense now, thank you so much! (And also: yes, I keep mixing up copy and clone, thanks for pointing that out.)

Or at least, it feels like it makes sense now. I'm sure I'll wrestle with the borrow checker some more in the future 😅

@zseri Wait a minute - the iterator inside isn't evaluated yet? You mean the one inside `flat_map`? Then when does that get evaluated?

@VincentTunru Rust has a rather confusing aspect where .iter() will yield references to values, even if the type is Copy. That causes borrow troubles later. In your case, you could use .into_iter() instead.

@VincentTunru seems there's already an answer, but they forgot to upvote your question, so I just did :D

Sign in to participate in the conversation

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.