84 lines
1.3 KiB
Plaintext
84 lines
1.3 KiB
Plaintext
// adds a and b, but also 4 for some reason
|
|
fn add(a: I32, b: I32): I32 {
|
|
let foo = 4; // because I feel like it
|
|
let test_float: F32 = {
|
|
10.2
|
|
};
|
|
test_float = 5.0;
|
|
a + b + foo
|
|
}
|
|
|
|
fn subtract(a: I32, b: I32): I32 {
|
|
a - b
|
|
}
|
|
|
|
fn return_type_test(a: F64): F64 {
|
|
return a * 2.0;
|
|
}
|
|
|
|
fn i_hate_this(a: F64): F64 {
|
|
return {
|
|
return {
|
|
return a;
|
|
};
|
|
};
|
|
}
|
|
|
|
fn unit_function() {
|
|
let a: I32 = 4;
|
|
}
|
|
|
|
fn main(): I32 {
|
|
add(4, subtract(5, 2))
|
|
}
|
|
|
|
|
|
fn returns_user(): User {
|
|
return User{
|
|
id: 4,
|
|
};
|
|
}
|
|
|
|
fn get_user_id(): U64 {
|
|
let user = returns_user();
|
|
user.id = 5;
|
|
return user.id;
|
|
}
|
|
|
|
fn use_method(user: User): U64 {
|
|
return user.get_id();
|
|
}
|
|
|
|
type User struct {
|
|
id: U64,
|
|
}
|
|
|
|
impl User {
|
|
fn new(id: U64): Self {
|
|
return Self{
|
|
id: id,
|
|
};
|
|
}
|
|
|
|
fn get_id(self: Self): U64 {
|
|
return self.id;
|
|
}
|
|
}
|
|
|
|
type TestTrait trait {
|
|
fn classMethod(id: I64): Self;
|
|
fn instanceMethod(self: Self): I64;
|
|
fn defaultImpl(self: Self): I64 {
|
|
return self.instanceMethod;
|
|
}
|
|
}
|
|
|
|
impl TestTrait for User {
|
|
fn classMethod(id: I64): Self {
|
|
return User{id: id,};
|
|
}
|
|
fn instanceMethod(self: Self): I64 {
|
|
return self.get_id();
|
|
}
|
|
}
|