https://pantsbuild.org/ logo
a

average-vr-56795

09/29/2017, 5:07 PM
Feels like a thing you could sugar away by having the and_then(|value|...) closure have a pointer to an anonymous temporary variable if you wanted, but they don't, so I need to pull out a named variable
w

witty-crayon-22786

09/29/2017, 5:27 PM
Mm, right. Alternatively, I think if you don't unwrap in that case what passes through the chain is the MutexGuard, which keeps the reference alive...?
Copy code
foo.and_then(|arcmutex| arcmutex.deref().lock()).and_then(|guard| do_something_with(guard.unwrap().get(|hashmap| hashmap.get(bar)))
? ...but with regard to locks, i'm ok with being slightly more explicit
i've returned the guard out of functions before, and it feels like a filthy abstraction leak, heh.
a

average-vr-56795

09/29/2017, 5:29 PM
guard still needs to be in scope everywhere that the ouptut from the hashmap is used, I think
Which means forcing extra nesting 😞
w

witty-crayon-22786

09/29/2017, 5:32 PM
ah, yes. unless you copy.
a

average-vr-56795

09/29/2017, 5:33 PM
And I'm also vaguely ok with that for Mutexes, but I've run into other cases where it was just a straight ownership thing which was kind of annoying 🙂
w

witty-crayon-22786

09/29/2017, 5:34 PM
yep
a

average-vr-56795

09/29/2017, 5:34 PM
I generally like these to be equivalent: foo.bar; let tmp = foo; tmp.bar;
And I keep just bumping into places where they're not 🙂