code implemented on 11_struct directory

This commit is contained in:
Vinicius Silva 2023-12-29 14:05:24 -03:00
parent e7787fca52
commit c84fde6772
5 changed files with 92 additions and 0 deletions

View File

@ -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")
}

17
11_structs/anonymous.v Normal file
View File

@ -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'
}

11
11_structs/static_types.v Normal file
View File

@ -0,0 +1,11 @@
struct User{}
fn User.new() User{
return User{}
}
pub fn main(){
user := User.new()
println(user)
}

View File

@ -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
}

View File

@ -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)
}