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:
parent
0d6d6f7de8
commit
8d0fe3894a
24
doc/docs.md
24
doc/docs.md
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user