amethyst / shred

Shared resource dispatcher

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to implement SystemData for Option<CustomRead>?

opened this issue · comments

I have some custom Reader similar to ReadStorage in specs and for this type it makes sense to have an Option<CustomRead> variant and to have an impl<'a, T> SystemData<'a> for Option<CustomRead>>

As neither SystemData<'a> nor Option<T> is defined in the current crate, the complier gives the usual "type parameter T must be used as the type parameter for some local type" error.

Is there any workaround to solve this issue ?
Would it be solved if shred implemented impl<'a,T> SystemData<'a> for Option<T> ?

commented

There are already implementations of SystemData for Option<Read> and Option<Write>.

I don't see a reason why those couldn't be replaced with: impl<'a, T: SystemData> SystemData<'a> for Option<T>

I don't see a reason why those couldn't be replaced with: impl<'a, T: SystemData> SystemData<'a> for Option

Hmm, but that doesn't work; there's no "optional fetching" for SystemData, just for resources.

commented

Ah yeah, not sure what to do then.

I don't think we can do this generically; you'll have to implement SystemData for a newtype instead.

Thanks, i've managed to refactor my code to use original Read/Write + Option for now.