H-advanced/Traits.rs hinzugefügt

main
Vincent Laux 2026-06-16 01:50:12 +02:00
parent c4f93b7ab0
commit 9e987d3c9b
1 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,20 @@
// 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)
}
}