I'm working on an ECS system that automatically multithreads systems (similar to bevvy). However sometimes third party libraries don't play nice with multithreading. Bevvy's answer is resources, but for me I'd like to allow my components (structs) to be sync or non-sync. Then if a system requires access to a non-sync struct, it will run on the main thread. An example I ran into early was SDL whose context requires being on the main thread.
My current API works something like this
world.add_system(my_system) // where my_system implements IntoSystem<TSystem>
The best solution I could come up with is having different methods and types, something like
world.add_single_threaded_system(other_system)
but I really would like to use a single method call to add a system, and have my library determine if that system is also sync. But I'm stuck on what this single method would take as a parameter, and how I could then sort this system into a collection of sync systems that can then be sent to a thread pool, or single threaded systems that would not support that.
So I effectively want something like
fn add_system(system: impl IntoSystem<TSystem>) where TSystem: System + Sync?
I thought about having systems implement traits, but the blanket impls would conflict, since every System + Sync would also be just System.
Any suggestions? Or give up and use a different API?