
Specialization in Rust and Why It Is Still Unstable
Specialization would let a blanket impl have faster special cases. After years of work it is still nightly only, held back by soundness problems with lifetimes.
Tag
9 posts

Specialization would let a blanket impl have faster special cases. After years of work it is still nightly only, held back by soundness problems with lifetimes.

Rust needs no DI container. Define a trait for the dependency, take it in the constructor and wire the real types in main. Tests pass a fake instead.

Rust forbids adding inherent methods to foreign types, but a trait you define can. Extension traits are how itertools, futures and tokio add methods to the standard library.

The orphan rule says you can implement a trait only if the trait or the type is yours. See why it exists, the usual errors and the standard workarounds.

A blanket implementation implements a trait for every type that meets a bound. See how ToString and Into work, the coherence rules that limit you and a safe pattern.

A supertrait says a trait requires another one. See the syntax, how methods are inherited, trait objects with supertraits and upcasting.

Trait bounds say what a generic type must be able to do. Learn the T: Trait syntax, where clauses, multiple bounds and when each form reads better.

A trait is a named set of methods a type promises to provide. See how to define one, implement it, give it default methods and use it as a bound.

A guide to choosing between generics, impl Trait, trait objects and enums in Rust, with one example solved four ways and the costs of each.