57 lines
942 B
Plaintext
57 lines
942 B
Plaintext
pub class Animal<T> {
|
|
pub name String;
|
|
pub val T;
|
|
|
|
constructor() {
|
|
self.name = "Rex".to_string();
|
|
}
|
|
|
|
pub fn speak(*self) {
|
|
println!("Unknown");
|
|
}
|
|
|
|
pub fn test_speak(*self) {
|
|
self.speak();
|
|
}
|
|
}
|
|
|
|
pub class Mammal<T> : Animal<T> {
|
|
constructor() {
|
|
unsafe {
|
|
std::ptr::write(&mut super, Super::new());
|
|
}
|
|
}
|
|
|
|
pub fn args_test(*self, x i32, y *str) {}
|
|
|
|
pub fn returning<'a>(*self) *'a str {
|
|
"Mammal"
|
|
}
|
|
}
|
|
|
|
pub class Dog : Mammal<i32> {
|
|
constructor() {
|
|
unsafe {
|
|
std::ptr::write(&mut super, Super::new());
|
|
}
|
|
}
|
|
|
|
pub override(Animal<i32>) fn speak(*self) {
|
|
println!("Woof!");
|
|
}
|
|
|
|
pub override fn returning(*self) *str {
|
|
"Dog"
|
|
}
|
|
}
|
|
|
|
pub fn run_tests() {
|
|
let dawg = Dog::new();
|
|
|
|
dawg.args_test(10, "hello");
|
|
|
|
dawg.test_speak();
|
|
|
|
println!("{}", dawg.returning());
|
|
}
|