Skip to content

Commit

Permalink
feat: add clone_inner to task_local
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fenoll <[email protected]>
  • Loading branch information
fenollp committed Apr 6, 2024
1 parent deff252 commit d01d5c9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tokio/src/task/task_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,19 @@ impl<T: Copy + 'static> LocalKey<T> {
}
}

impl<T: Clone + 'static> LocalKey<T> {
/// Returns a clone of the task-local value
/// if the task-local value implements `Clone`.
///
/// # Panics
///
/// This function will panic if the task local doesn't have a value set.
#[track_caller]
pub fn clone_inner(&'static self) -> T {
self.with(|v| v.clone())
}
}

impl<T: 'static> fmt::Debug for LocalKey<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("LocalKey { .. }")
Expand Down

0 comments on commit d01d5c9

Please sign in to comment.