11_structs directory created
This commit is contained in:
parent
62e0326bc9
commit
e7787fca52
|
|
@ -0,0 +1,11 @@
|
|||
struct Foo{
|
||||
n int // Default is 0
|
||||
s string // Default is ''
|
||||
a []int // Default is []int{}
|
||||
pos int = -1 // Default is -1
|
||||
}
|
||||
|
||||
pub fn main(){
|
||||
mut f := Foo{1,'Test', [12,3,5,3,6], -2}
|
||||
println(f)
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
struct Point{
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn main(){
|
||||
p := &Point{10,10}
|
||||
println(p.x)
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
struct Foo{
|
||||
mut:
|
||||
x int
|
||||
}
|
||||
|
||||
pub fn main(){
|
||||
fa := Foo{1}
|
||||
mut a := fa
|
||||
a.x = 2
|
||||
assert fa.x == 1
|
||||
assert a.x == 2
|
||||
|
||||
mut fc := Foo{1}
|
||||
mut c := &fc
|
||||
|
||||
c.x = 2
|
||||
assert fc.x == 2
|
||||
assert c.x == 2
|
||||
|
||||
println(fc)
|
||||
println(c)
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
struct Point{
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
pub fn main(){
|
||||
mut p := Point{x: 10, y: 20}
|
||||
|
||||
assert p.x == 10
|
||||
|
||||
mut p1 := Point{x: 30, y: 4}
|
||||
|
||||
assert p1.y == 4
|
||||
point := [Point{x: 10, y: 20},Point{x: 20, y: 30},Point{x: 30, y: 40}]
|
||||
println(point)
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
struct Foo{
|
||||
m int @[required]
|
||||
n string
|
||||
}
|
||||
|
||||
pub fn main(){
|
||||
mut a := Foo{1, ''}
|
||||
assert a.m == 1
|
||||
|
||||
_ := Foo{1,'Test'}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
struct Point{
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
pub fn main(){
|
||||
mut p := Point{x: 10, y: 20}
|
||||
println('${p.x} | ${p.y}')
|
||||
|
||||
|
||||
p1 := Point{10, 20}
|
||||
assert p1.x == 10
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue