Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"scoped_thread_local!(...)" can be improved #1112

Open
Diggsey opened this issue May 10, 2015 · 0 comments
Open

"scoped_thread_local!(...)" can be improved #1112

Diggsey opened this issue May 10, 2015 · 0 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Comments

@Diggsey
Copy link
Contributor

Diggsey commented May 10, 2015

Currently it's impossible to store structs with lifetime bounds in a scoped thread local, largely because rust doesn't support HKT. However, with macros and associated types, the type system is just powerful enough to express the required semantics.

Using the example implementation below, one can write code like the following:

scoped_thread_local!(static EXAMPLE: for<'scope> &'scope MutexGuard<'scope, u32>);

The presence of 'scope allows a much wider range of types to be stored safely in a scoped thread local. Without this change the only way to get the same behaviour is via the use of unsafe code.

Example implementation:
https://github.com/Diggsey/rust/tree/scoped_thread_local_hkt

(While it requires no changes to the compiler, changes to the compiler could make it significantly less hacky...)

@nrc nrc added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Aug 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

2 participants