Last active
February 25, 2025 01:40
-
-
Save estevaofon/7f7dec7ed4164d1cfe4c16bf26bc882a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Define a trait with a default method implementation. | |
| trait Greet { | |
| fn greet(&self) { | |
| println!("Hello from the default implementation!"); | |
| } | |
| } | |
| // Define a type. | |
| struct Person; | |
| // Implement the trait for the type using a blank implementation. | |
| // This means Person uses the default implementation of greet(). | |
| impl Greet for Person {} | |
| fn main() { | |
| let person = Person; | |
| person.greet(); // Prints: "Hello from the default implementation!" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment