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:
15
doc/docs.md
15
doc/docs.md
@@ -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' />
|
||||
|
||||
|
Reference in New Issue
Block a user