1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

doc: document anonymous structs

This commit is contained in:
Alexander Medvednikov 2022-07-14 11:06:10 +03:00 committed by GitHub
parent 0d6d6f7de8
commit 8d0fe3894a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2130,6 +2130,30 @@ Private fields are available only inside the same [module](#modules), any attemp
to directly access them from another module will cause an error during compilation. to directly access them from another module will cause an error during compilation.
Public immutable fields are readonly everywhere. Public immutable fields are readonly everywhere.
### Anonymous structs
V supports anonymous structs: structs that don't have to be declared separately
with a struct name.
```
struct Book {
author struct {
name string
age int
}
title string
}
book := Book{
author: struct {
name: 'Samantha Black'
age: 24
}
}
assert book.author.name == 'Samantha Black'
assert book.author.age == 24
```
### Methods ### Methods
```v ```v