Closed
Description
Feature gate: #![feature(local_key_cell_methods)]
This is a tracking issue for thread local Cell methods: RFC 3184.
Public API
impl<T: 'static> LocalKey<Cell<T>> {
pub fn set(&'static self, value: T);
pub fn get(&'static self) -> T where T: Copy;
pub fn take(&'static self) -> T where T: Default;
pub fn replace(&'static self, value: T) -> T;
}
impl<T: 'static> LocalKey<RefCell<T>> {
pub fn with_borrow<F, R>(&'static self, f: F) -> R where F: FnOnce(&T) -> R;
pub fn with_borrow_mut<F, R>(&'static self, f: F) -> R where F: FnOnce(&mut T) -> R;
pub fn set(&'static self, value: T);
pub fn take(&'static self) -> T where T: Default;
pub fn replace(&'static self, value: T) -> T;
}
Steps / History
- RFC: Thread local Cell methods. rfcs#3184
- Implementation: Implement RFC 3184 - thread local cell methods #92123
- Final comment period (FCP): Tracking issue for thread local Cell methods #92122 (comment)
- Stabilization PR: Stabilize thread local cell methods. #114689
Unresolved Questions
Is the behavior ofYes.set()
(to skip the default initialization) the right behavior?- Are there any other types commonly used as thread locals for which we should do something similar?
- Do we also want anything for
UnsafeCell
? MaybeLocalKey<UnsafeCell<T>>::get()
to get the*mut T
, just likeUnsafeCell<T>::get()
. - Not a blocker for stabilizing this feature. Methods for other types can be a separate feature.
- Do we also want anything for