code implemented on 11_struct directory
This commit is contained in:
parent
e7787fca52
commit
c84fde6772
|
|
@ -0,0 +1,16 @@
|
||||||
|
struct Foo{
|
||||||
|
a int
|
||||||
|
mut:
|
||||||
|
b int
|
||||||
|
c int
|
||||||
|
pub:
|
||||||
|
d int
|
||||||
|
pub mut:
|
||||||
|
e int
|
||||||
|
__global:
|
||||||
|
f int
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main(){
|
||||||
|
println("OI")
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
struct Book{
|
||||||
|
author struct {
|
||||||
|
name string
|
||||||
|
age int
|
||||||
|
}
|
||||||
|
|
||||||
|
title string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn main(){
|
||||||
|
book := Book{author: struct{name: 'Samantha Black', age: 23}, title: 'Livro'}
|
||||||
|
|
||||||
|
assert book.author.name == 'Samantha Black'
|
||||||
|
assert book.author.age == 23
|
||||||
|
assert book.title == 'Livro'
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
struct User{}
|
||||||
|
|
||||||
|
fn User.new() User{
|
||||||
|
return User{}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main(){
|
||||||
|
user := User.new()
|
||||||
|
println(user)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
@[params]
|
||||||
|
struct ButtonConfig{
|
||||||
|
text string = 'oi'
|
||||||
|
is_disabled bool
|
||||||
|
width int = 70
|
||||||
|
height int //= 20
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Button{
|
||||||
|
text string
|
||||||
|
width int
|
||||||
|
height int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_button(c ButtonConfig) &Button{
|
||||||
|
return &Button{
|
||||||
|
width: c.width
|
||||||
|
height: c.height
|
||||||
|
text: c.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main(){
|
||||||
|
button := new_button()
|
||||||
|
assert button.height == 0
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
struct User{
|
||||||
|
name string
|
||||||
|
age int
|
||||||
|
is_registered bool
|
||||||
|
}
|
||||||
|
|
||||||
|
fn register(u User) User{
|
||||||
|
return User{
|
||||||
|
...u
|
||||||
|
is_registered: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main(){
|
||||||
|
mut user := User{
|
||||||
|
name: 'abc'
|
||||||
|
age: 23
|
||||||
|
}
|
||||||
|
|
||||||
|
user = register(user)
|
||||||
|
println(user)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue