Skip to main content
A default implementation in Rust occurs when a trait provides a concrete method body rather than just a method signature. When a type implements the trait, it automatically inherits this default behavior unless the implementor explicitly overrides the method with a custom definition.

Syntax and Mechanics

To define a default implementation, replace the trailing semicolon of a trait method signature with a block containing the method body.
When implementing the trait for a specific type, you are only required to define methods that lack a default.

Technical Characteristics

Internal Trait Resolution Default implementations can invoke other methods defined within the same trait, including methods that do not have default implementations. The compiler guarantees that any type implementing the trait will provide the required methods, making the internal call safe at compile time.
No Super/Base Delegation Unlike class inheritance in object-oriented languages, Rust does not provide a mechanism for an overriding method to call the default implementation (e.g., there is no super::method_name() equivalent). Once a type overrides a default method, the original default implementation is entirely shadowed and inaccessible for that specific type. Associated Constants and Generic Type Parameters Traits can also provide default values for associated constants and generic type parameters.
Blanket Implementations vs. Default Implementations A default implementation is bound to the trait definition itself and applies to types explicitly implementing that trait. This differs from a blanket implementation (impl<T> Trait for T), which automatically implements a trait for any type satisfying specific bounds, without requiring an explicit impl block for the target type.
Tired of Poor Rust Skills? Fix That With Deep Grasping!Learn More