Heading off a non-answer: if it's "mostly a stylistic decision," discuss stylistic preferences and their reasons. What makes one choice more attractive or more ugly than another?
-
-
Prikaži ovu nitHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
I'm 90% positive you could have a type parameter on the trait, and associated type (so far: this is TryFrom) and a type parameter on each method (I think serde has some of this).
- Još 1 odgovor
Novi razgovor -
-
-
Associated types when I need "some" generic type. Generic on the trait for when a method on that trait is generic over a single type in its parameters. And I rarely use generics on fn since that is not object safe but it can be useful if you have a specific situation for them.
-
The cost of AT vs Generic on the trait really depends but generally also comes down to how you use the trait. AT can "hide" some specific type within the trait which is _not_ generic to that trait implementation. Generics are more ergonomically costly than AT but are more flexy.
- Još 3 druga odgovora
Novi razgovor -
-
-
Generic type parameters on traits are useful if you want to impl the trait repeatedly for different types. They’re also the easiest path to object safety (e.g. generic method params aren’t object safe)
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
https://doc.rust-lang.org/book/ch19-03-advanced-traits.html … explains the differences pretty well :-)
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
type param on trait: if you need to impl it more than once for a given type otherwise, associated type, or generic param on fn depending on how much object safety (dyn safety) matters to you
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
If on the trait or associated, it’s an existential, allowing the implementation to optimize around the choice of type. If on the methods within it’s a universal, and nothing particular is known by any implementation.
Hvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.