Added items

This commit is contained in:
2026-06-16 13:15:01 +02:00
parent fa6765cdd9
commit e4fbab190c
8 changed files with 366 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
pub module trait_test;
trait Speak {
fn String speak(*self);
}
trait Greet : Speak {
fn String greet(*self);
}
struct Dog {
name String,
}
impl Speak for Dog {
fn String speak(*self) {
"woof".to_string()
}
}
impl Greet for Dog {
fn String greet(*self) {
"hello".to_string()
}
}
pub fn void test_trait_impl() {
let d = Dog { name: "Rex".to_string() };
assert_eq!(d.speak(), "woof");
}
pub fn void test_trait_with_requirement() {
let d = Dog { name: "Buddy".to_string() };
assert_eq!(d.speak(), "woof");
assert_eq!(d.greet(), "hello");
}
pub fn void run_tests() {
test_trait_impl();
test_trait_with_requirement();
}