Function task::get_my_current_task

source ·
pub fn get_my_current_task() -> Option<TaskRef>
Expand description

Returns a cloned reference to the current task.

Using with_current_task() is preferred because it operates on a borrowed reference to the current task and avoids cloning that reference.

This function must clone the current task’s TaskRef in order to ensure that this task cannot be dropped for the lifetime of the returned TaskRef. Because the “current task” feature uses thread-local storage (TLS), there is no safe way to avoid the cloning operation because it is impossible to specify the lifetime of the returned thread-local reference in Rust.