logoalt Hacker News

Suractoday at 6:24 AM3 repliesview on HN

As a non Rust man, how real are the problems in this article? Does it show up in real word or is it just a edge case? I only program in C17, C++ as C with classes and C#. Anyone can give me a good read what Traits even are?


Replies

swiftcodertoday at 8:01 AM

> As a non Rust man, how real are the problems in this article?

Real, but of more concern to folks designing widely-used libraries than to folks using said libraries.

> Anyone can give me a good read what Traits even are?

You can think of traits as analogous to interfaces in OOP languages (i.e. pure virtual abstract classes in C++ terminology).

They just define a set of methods that types can implement to conform to the trait, and then consumers can treat implementing types as if they were the trait.

The major differences are: traits are implemented outside the actual type implementation, so arbitrary trait implementations can be added after the type has been written (this is why we need coherence), and rust uses traits as compile-time bounds for generics (templates).

krecotoday at 11:57 AM

Another imprecise analogy would be to see traits as operators.

You decide to define the operator "serde::serialize" for "MyType" but then your are stuck because you can't override or select different operators for "MyType" because only one can exists.

That's a regular yet not super common issue with traits (and this is not exclusive to Rust). It's quite irritating because you wouldn't expect this from languages with this degree of modularity.

selfmodruntimetoday at 11:04 AM

Very real for library developers if the ecosystem started to slow down. Nonexistent for current consumers of libraries and application developers.