Skip to content

Instantly share code, notes, and snippets.

@estevaofon
Last active February 25, 2025 01:40
Show Gist options
  • Select an option

  • Save estevaofon/7f7dec7ed4164d1cfe4c16bf26bc882a to your computer and use it in GitHub Desktop.

Select an option

Save estevaofon/7f7dec7ed4164d1cfe4c16bf26bc882a to your computer and use it in GitHub Desktop.
// 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