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

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

Open
akanalytics opened this issue Jun 12, 2024 · 1 comment

Comments

@akanalytics
Copy link

akanalytics commented Jun 12, 2024

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
Copy link
Owner

Amanieu commented Jun 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants