task: make LocalKey::get work with Clone types (#6433)

Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
This commit is contained in:
Pierre Fenoll 2024-04-10 11:41:58 +02:00 committed by GitHub
parent be9328da75
commit ccee1d4493
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -264,16 +264,16 @@ impl<T: 'static> LocalKey<T> {
}
}
impl<T: Copy + 'static> LocalKey<T> {
impl<T: Clone + 'static> LocalKey<T> {
/// Returns a copy of the task-local value
/// if the task-local value implements `Copy`.
/// 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 get(&'static self) -> T {
self.with(|v| *v)
self.with(|v| v.clone())
}
}