Feels like a thing you could sugar away by having ...
# development
a
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
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
guard still needs to be in scope everywhere that the ouptut from the hashmap is used, I think
Which means forcing extra nesting 😞
w
ah, yes. unless you copy.
a
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
yep
a
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 🙂