Function task::with_current_task_and_value
source · pub fn with_current_task_and_value<F, R, T>(
function: F,
value: T
) -> Result<R, T>where
F: FnOnce(&TaskRef, T) -> R,
Expand description
Similar to with_current_task()
, but also accepts a value that is
passed to the given function
or returned in the case of an error.
This is useful for two reasons:
- Like
with_current_task()
, it avoids cloning a reference to the current task. - It allows the
value
to be returned upon an error, instead of the behavior inwith_current_task()
that unconditionally takes ownership of thevalue
without any way to recover ownership of thatvalue
.
Returns an Err
containing the value
if the current task cannot be obtained.