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
Unresolved Questions
Is the behavior of set() (to skip the default initialization) the right behavior? Yes.
- Are there any other types commonly used as thread locals for which we should do something similar?
- Do we also want anything for
UnsafeCell? Maybe LocalKey<UnsafeCell<T>>::get() to get the *mut T, just like UnsafeCell<T>::get().
- Not a blocker for stabilizing this feature. Methods for other types can be a separate feature.
Feature gate:
#![feature(local_key_cell_methods)]This is a tracking issue for thread local Cell methods: RFC 3184.
Public API
Steps / History
Unresolved Questions
Is the behavior ofYes.set()(to skip the default initialization) the right behavior?UnsafeCell? MaybeLocalKey<UnsafeCell<T>>::get()to get the*mut T, just likeUnsafeCell<T>::get().