I'd like the ability to have the value borrowed from a sync::watch::Receiver be discriminated when doing a wait_for so that the caller does not have to repeat that discrimination (eg. if in the process of waiting for an Option to be Some - it'd be nice not to then have to extract the Some from the Option again when actually getting the data out of the watch).
Describe the solution you'd likewait_for_map as described in the original wait_for request seems reasonable. With the Option variants being the morale equivalent of the bool variants in wait_for.
Describe alternatives you've considered
Generally an unwrap in this scenario seems "safe-ish"; the developer does in fact have SOME confidence that the value is in fact already discriminated. Though there is the risk that the wait_for condition is updated without updating the subsequent unwrap or vice-versa.
Simply repeating the logic subsequent to the wait_for works; though is a bit verbose (and has the same issues with repeated logic needing to be kept in sync) - particularly because the wait_for provides the engine for "what to do if the condition does not hold (wait and try again next time)".
Additional context
The code in question is a watch that may contain None - the code wait_fors the value to be Some and then fetches it - receiving an Option that it needs to extract a value from.
I had a quick look at doing this myself thinking it was probably trivial - the apparent lack of a map on parking_lot::RwLockGuard seems to imply its NOT trivial to just discriminate the inner value while maintaining the borrow.
I'm sorry, but we won't add this. Like you noticed yourself, it's non-trivial to implement, and you can repeat the logic yourself by wrapping the unwrapping logic in a function call.
I'd like the ability to have the value borrowed from a
sync::watch::Receiver
be discriminated when doing await_for
so that the caller does not have to repeat that discrimination (eg. if in the process of waiting for anOption
to beSome
- it'd be nice not to then have to extract theSome
from theOption
again when actually getting the data out of the watch).Describe the solution you'd like
wait_for_map
as described in the originalwait_for
request seems reasonable. With theOption
variants being the morale equivalent of thebool
variants inwait_for
.Describe alternatives you've considered
wait_for
condition is updated without updating the subsequentunwrap
or vice-versa.wait_for
works; though is a bit verbose (and has the same issues with repeated logic needing to be kept in sync) - particularly because thewait_for
provides the engine for "what to do if the condition does not hold (wait and try again next time)".Additional context The code in question is a
watch
that may containNone
- the codewait_for
s the value to beSome
and then fetches it - receiving anOption
that it needs to extract a value from.I had a quick look at doing this myself thinking it was probably trivial - the apparent lack of a
map
onparking_lot::RwLockGuard
seems to imply its NOT trivial to just discriminate the inner value while maintaining the borrow.