21 lines
384 B
Rust
21 lines
384 B
Rust
// Trait-Definition
|
|
trait Gruss {
|
|
fn begruesse(&self) -> String;
|
|
}
|
|
|
|
struct Deutsch { name: String }
|
|
struct Englisch { name: String }
|
|
|
|
// Trait implementieren
|
|
impl Gruss for Deutsch {
|
|
fn begruesse(&self) -> String {
|
|
format!("Hallo, {}!", self.name)
|
|
}
|
|
}
|
|
|
|
impl Gruss for Englisch {
|
|
fn begruesse(&self) -> String {
|
|
format!("Hello, {}!", self.name)
|
|
}
|
|
}
|