Amanieu / thread_local-rs

Per-object thread-local storage for Rust
Apache License 2.0
328 stars 41 forks source link

Potential solution for `get_mut` without requiring runtime checking (e.g. `RefCell`) #60

Open AshleySchaeffer opened 1 year ago

AshleySchaeffer commented 1 year ago

Based on a brief exchange with @Kestrer:

https://github.com/Amanieu/thread_local-rs/issues/31#issuecomment-1674568797

After a quick look, I think it would require a fairly significant API rework that employs the use of guards (perhaps ThreadLocalGuard and ThreadLocalMutGuard) that could maybe impl Deref and DerefMut to the underlying value. In much the same way as IterMut is implemented:

https://docs.rs/thread_local/latest/src/thread_local/lib.rs.html#468-471

Scratch that, I think I may have a working implementation.

Nope, yeah I think guards may be needed

AshleySchaeffer commented 1 year ago

OK after a fundamental Rust refresher, I think my original comment is partly correct. However, you have to also add a get_inner_mut method. I'll see if I can do a PR.