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

docs: document the [required] struct attribute (#6956)

This commit is contained in:
spaceface777
2020-11-27 14:37:12 +01:00
committed by GitHub
parent 5ba5a53b77
commit bbea7fb91f
3 changed files with 17 additions and 2 deletions

View File

@@ -1139,6 +1139,21 @@ Array and map fields are allocated.
It's also possible to define custom default values.
### Required fields
```v
struct Foo {
n int [required]
}
```
You can mark a struct field with the `[required]` attribute, to tell V that
that field must be initialized when creating an instance of that struct.
This example will not compile, since the field `n` isn't explicitly initialized:
```v failcompile
_ = Foo{}
```
<a id='short-struct-initialization-syntax' />