Welp, just posted my first StackOverflow question as a result of my first fight with the #Rust borrow checker, as is tradition. Now to wait until it's closed as a duplicate.
But if anyone has any pointers (hehe), would appreciate: https://stackoverflow.com/questions/70286206/why-may-a-closure-outlive-the-current-function-by-borrowing-a-u32
@amapanda Heh I can imagine. It helps to have friends doing the same thing, but even then I'm quite sure I'm not going to complete all of the exercises in time :)
@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
Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.