Amanieu / thread_local-rs

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

Remove T: Send as a trait bound on the struct and just rely on method bounds #77

Open akanalytics opened 3 months ago

akanalytics commented 3 months ago

I understand that T: Send is a requirement for ThreadLocal to function, but could the Send bound be removed from the struct definition and just retained for method impls.

This would greatly simply generic struct definitions, which nest structs containing a ThreadLocal. Currently the Send bound propagates, even to impls of structs containing thread locals that don't make use of the actual thread local or any of its methods.

Obviously where methods of the ThreadLocal are called then the trait bound is needed.

Use case: I have a struct A, which is contained in struct B, which is contained in struct C etc. If I add a ThreadLocal to A (to count method invocations say or method invocation timing metrics), then B, C and so on, all need to declare T:Send. As do trait impls such as impl Display for C, PAartialEq it seems.

Amanieu commented 3 months ago

Sure, that sounds fine! Would you like to submit a PR for this?