mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
docs: document the purpose of the [params]
trailing struct tag
This commit is contained in:
parent
655b5c563a
commit
508f29c101
@ -1853,6 +1853,7 @@ V doesn't have default function arguments or named arguments, for that trailing
|
||||
literal syntax can be used instead:
|
||||
|
||||
```v
|
||||
[params]
|
||||
struct ButtonConfig {
|
||||
text string
|
||||
is_disabled bool
|
||||
@ -1887,6 +1888,13 @@ new_button(ButtonConfig{text:'Click me', width:100})
|
||||
|
||||
This only works for functions that take a struct for the last argument.
|
||||
|
||||
NB: the `[params]` tag is used to tell V, that the trailing struct parameter
|
||||
can be ommited *entirely*, so that you can write `button := new_button()`.
|
||||
Without it, you have to specify *at least* one of the field names, even if it
|
||||
has its default value, otherwise the compiler will produce this error message,
|
||||
when you call the function with no parameters:
|
||||
`error: expected 1 arguments, but got 0`.
|
||||
|
||||
### Access modifiers
|
||||
|
||||
Struct fields are private and immutable by default (making structs immutable as well).
|
||||
|
Loading…
Reference in New Issue
Block a user