-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct_params.ko
More file actions
41 lines (33 loc) · 834 Bytes
/
struct_params.ko
File metadata and controls
41 lines (33 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module struct_params {
meta {
purpose: "Demonstrate structs as function parameters and return values",
version: "0.1.0"
}
struct Point {
x: Int,
y: Int
}
fn get_x(ref p: Point) -> Int {
return p.x
}
fn get_y(ref p: Point) -> Int {
return p.y
}
fn make_point(x: Int, y: Int) -> Point {
return Point { x: x, y: y }
}
fn add_points(ref a: Point, ref b: Point) -> Point {
return Point { x: a.x + b.x, y: a.y + b.y }
}
fn main() {
let p: Point = Point { x: 10, y: 20 }
print_int(get_x(p))
print_int(get_y(p))
let q: Point = make_point(30, 40)
print_int(q.x)
print_int(q.y)
let r: Point = add_points(p, q)
print_int(r.x)
print_int(r.y)
}
}