diff --git a/11_structs/access_structs.v b/11_structs/access_structs.v new file mode 100644 index 0000000..2a47912 --- /dev/null +++ b/11_structs/access_structs.v @@ -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") +} \ No newline at end of file diff --git a/11_structs/anonymous.v b/11_structs/anonymous.v new file mode 100644 index 0000000..153b9d9 --- /dev/null +++ b/11_structs/anonymous.v @@ -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' +} \ No newline at end of file diff --git a/11_structs/static_types.v b/11_structs/static_types.v new file mode 100644 index 0000000..bb4c1c2 --- /dev/null +++ b/11_structs/static_types.v @@ -0,0 +1,11 @@ + +struct User{} + +fn User.new() User{ + return User{} +} + +pub fn main(){ + user := User.new() + println(user) +} \ No newline at end of file diff --git a/11_structs/trailing_structs.v b/11_structs/trailing_structs.v new file mode 100644 index 0000000..3650246 --- /dev/null +++ b/11_structs/trailing_structs.v @@ -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 +} \ No newline at end of file diff --git a/11_structs/update_struct.v b/11_structs/update_struct.v new file mode 100644 index 0000000..88383de --- /dev/null +++ b/11_structs/update_struct.v @@ -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) +} \ No newline at end of file