How to make Rust trait like feature in dlang ?

lili akozhao at tencent.com
Mon Jun 17 15:45:34 UTC 2019


On Monday, 17 June 2019 at 14:39:06 UTC, XavierAP wrote:
> On Monday, 17 June 2019 at 10:25:57 UTC, lili wrote:
>
> I think you mean C++ "concepts"[1]?. These do exist in D (since 
> much earlier); they are called template constraints[2]:
>
> One difference is that D requires this "polymorphism" to be 
> templated, while C# and Rust allow structs to implement 
> interfaces/traits. (Probably there is no reason why D could or 
> should not add this capability, at least as long as it does not 
> turn structs from values to references when assigned to an 
> interface value.)
>
> This templated approach on the other hand is more flexible. 
> Inheritance is not a sin as many people say nowadays, but it 
> introduces rigidity in your design, and is not extensible for 
> library users.
> _______

Thanks your answer。 I just start learning dlang few days.




More information about the Digitalmars-d mailing list