2025-08-31 23:06:26 -06:00
|
|
|
fn main(): i64 {
|
|
|
|
|
let user = User{id: 4};
|
2025-10-09 17:40:54 -06:00
|
|
|
let result = user.instance_method() + User::instance_method(user);
|
|
|
|
|
return result;
|
2022-10-12 11:06:58 -06:00
|
|
|
}
|
2025-08-19 21:54:06 -06:00
|
|
|
|
|
|
|
|
type User struct {
|
|
|
|
|
id: i64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TestTrait trait {
|
|
|
|
|
fn class_method(id: i64): Self;
|
|
|
|
|
fn instance_method(self: Self): i64;
|
|
|
|
|
fn default_impl(self: Self): i64;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TestTrait for User {
|
|
|
|
|
fn class_method(id: i64): Self {
|
|
|
|
|
return Self{id: id};
|
|
|
|
|
}
|
|
|
|
|
fn instance_method(self: Self): i64 {
|
2025-08-25 21:51:50 -06:00
|
|
|
return self.id;
|
2025-08-19 21:54:06 -06:00
|
|
|
}
|
|
|
|
|
fn default_impl(self: Self): i64 {
|
|
|
|
|
return self.instance_method();
|
|
|
|
|
}
|
|
|
|
|
}
|