You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow type to create an alias for several trait bounds #8634
This is similar to defining a trait inheriting from both (trait Alias: Foo + Bar {}) but it's purely a synonym and doesn't have to be impl'd separately.
Reacted by jjpe, Evan Rose, Felipe S. S. Schneider, Aleksandr Petrosyan, Moritz Mahringer, Asuka Minato and Nathan Collins
It is, but only very weakly; the proposal here is literally just a synonym to make code shorter/nicer, so this could even be implemented via textual substitution, modulo scoping concerns (although this obviously shouldn't be the actual implementation).
other than the fact that these generic impls are slightly buggy. I guess a macro that expands to the above (assuming that pattern works) would be a solution.
(And the kind "inference" could just be checking that Foo is valid at the place it is used at those places.)
I don't see a compelling need for this, since you can just declare another empty trait that inherits from both. I realize it's somewhat more concise if you have the additional syntax, but it just doesn't seem to add enough value to justify adding a new feature. Closing.
Reacted by Nathan Collins, Wessel Kronemeijer, Don Vietnam and mochou
whereas simply deriving from AudioNode<OutputBuffer, OutputSample> would require you to impl both InputNode and AudioNode<OutputBuffer, OutputSample>, right?
I'm not sure about using the type keyword though. Could we just use trait? i.e.
Activity
glaebhoerl commentedon Aug 20, 2013
This is a subset of GHC's ConstraintKinds extension, and so also related to higher-kinded generics.
huonw commentedon Aug 21, 2013
It is, but only very weakly; the proposal here is literally just a synonym to make code shorter/nicer, so this could even be implemented via textual substitution, modulo scoping concerns (although this obviously shouldn't be the actual implementation).
glaebhoerl commentedon Aug 21, 2013
If you write
type Foo = BarI think you'd need some kind of kind inference at some point to figure out if it's a type or a trait.huonw commentedon Aug 21, 2013
The syntax could easily be something like
trait type Foo = Bar. Thinking about it now, I'm not sure how different this would be from:other than the fact that these generic impls are slightly buggy. I guess a macro that expands to the above (assuming that pattern works) would be a solution.
(And the kind "inference" could just be checking that
Foois valid at the place it is used at those places.)glaebhoerl commentedon Aug 21, 2013
In Haskell the two are indeed equivalent. (Modulo ability to partially apply them which is another higher-kinded generics thing Rust doesn't have.)
bblum commentedon Aug 22, 2013
reusing the type keyword for this would be confusing, as it's not a type at all. perhaps we could have a kind keyword.
glaebhoerl commentedon Aug 22, 2013
It is a type, just of a different kind ;), which is not first-class in Rust. Anyway I think the nicest syntax would be:
(but if generic impl bugs can be worked out there's probably not a pressing need)
catamorphism commentedon Nov 12, 2013
I don't see a compelling need for this, since you can just declare another empty trait that inherits from both. I realize it's somewhat more concise if you have the additional syntax, but it just doesn't seem to add enough value to justify adding a new feature. Closing.
mitchmindtree commentedon Nov 30, 2014
@catamorphism I think this would be handy for traits that have a number of type parameters i.e.
With this I imagine you could write
whereas simply deriving from
AudioNode<OutputBuffer, OutputSample>would require you toimplbothInputNodeandAudioNode<OutputBuffer, OutputSample>, right?I'm not sure about using the
typekeyword though. Could we just usetrait? i.e.emk commentedon Dec 12, 2014
I also would love to be able to write:
The workaround is simple enough, fortunately:
jonysy commentedon Mar 21, 2017
Similar to @emk's case, I'd love to be able to write:
instead of:
The first example is clear. The second, not so much.. @catamorphism will you consider reopening this issue?
jonysy commentedon Mar 21, 2017
@catamorphism another example (leaf)..
jonysy commentedon Mar 21, 2017
Ignore my comments. RFC#1733 is moving in this direction.
Auto merge of rust-lang#10990 - y21:issue8634-partial, r=blyxyas,xFre…
Merge rust-lang#8637