Skip to content

Tracking issue for thread local Cell methods #92122

Closed
@m-ou-se

Description

@m-ou-se

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions