This commit is contained in:
2026-06-05 12:32:12 +02:00
parent 0955bca5bc
commit d5501ef25e
14 changed files with 821 additions and 11 deletions
+39
View File
@@ -0,0 +1,39 @@
trait Speak {
String speak(self*);
}
struct Dog {
String name,
}
impl Speak for Dog {
String speak(self*) {
"woof"
}
}
pub void test_trait_impl() {
let d = Dog { name: "Rex" };
assert_eq!(d.speak(), "woof");
}
trait Greet : Speak {
String greet(self*);
}
impl Greet for Dog {
String greet(self*) {
"hello"
}
}
pub void test_trait_with_requirement() {
let d = Dog { name: "Buddy" };
assert_eq!(d.speak(), "woof");
assert_eq!(d.greet(), "hello");
}
pub void run_tests() {
test_trait_impl();
test_trait_with_requirement();
}