feat: signal traits should take associated types instead of generics #1578
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I initially began this as part of #1577, before realizing that that had a trait conflict with
Fn()
in any case and needed to use the concrete types instead. It was not possible to do something likebecause the compiler says
U
is unused. I guess because it's only used as the generic of the constraint onT
.This led me down a (short) path re: the difference between generics on traits and associated types. I think it's probably correct for these to be associated types rather than generics, because there truly only is one value, and it's provided by the implementor of the trait, not the caller: i.e., any
T: SignalGet
will always have someT::Value
which is the value it returns. It doesn't make sense to haveSignalGet<U>
: theSignalGet
trait itself isn't generic, i.e., we can't specify differentT
here and get anything else out of our.get()
call.@jquesada2016 this was your proposal originally of course. Does making this change make sense to you? I think it's probably more correct. No longer necessary for #1577 but if we're going to do it, we should do it now before 0.5 as it's breaking.