Top "Traits" questions

In computer programming, a trait is a collection of methods, used as a "simple conceptual model for structuring object oriented programs"

What is the difference between traits in Rust and typeclasses in Haskell?

Traits in Rust seem at least superficially similar to typeclasses in Haskell, however I've seen people write that there are …

haskell rust traits
How do I return an instance of a trait from a method?

I'm trying to create a function that returns an instance of the Shader trait. Here is my drastically simplified code: …

rust traits
I implemented a trait for another trait but cannot call methods from both traits

I have a trait called Sleep: pub trait Sleep { fn sleep(&self); } I could provide a different implementation of …

rust traits
How do I implement the Add trait for a reference to a struct?

I made a two element Vector struct and I want to overload the + operator. I made all my functions and …

reference rust traits lifetime
Scala: Mix traits and case class in pattern match

I want to match on some case classes. If I don't know them, I want to match on a specified …

scala pattern-matching traits case-class
Why can a Scala trait extend a class?

I see that traits in Scala are similar to interfaces in Java (but interfaces in Java extend other interfaces, they …

scala traits
Why is the `Sized` bound necessary in this trait?

I have a trait with two associated functions: trait WithConstructor: Sized { fn new_with_param(param: usize) -> Self; …

rust traits
(Re)named std::pair members

Instead of writing town->first I would like to write town->name. Inline named accessors (Renaming first and …

c++ templates stl typedef traits
Can traits have properties & methods with private & protected visibility? Can traits have constructor, destructor & class-constants?

I've never seen a single trait where properties and methods are private or protected. Every time I worked with traits …

php constructor visibility traits class-constants
Difference between @Delegate, @Mixin and Traits in Groovy?

Would someone explain when I would want to use Groovy Traits vs. Mixins (@Mixin) vs. Delegates (@Delegate)? Maybe some trade-offs …

design-patterns groovy delegates mixins traits