docs: document the purpose of the `[params]` trailing struct tag
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:
|
literal syntax can be used instead:
|
||||||
|
|
||||||
```v
|
```v
|
||||||
|
[params]
|
||||||
struct ButtonConfig {
|
struct ButtonConfig {
|
||||||
text string
|
text string
|
||||||
is_disabled bool
|
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.
|
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
|
### Access modifiers
|
||||||
|
|
||||||
Struct fields are private and immutable by default (making structs immutable as well).
|
Struct fields are private and immutable by default (making structs immutable as well).
|
||||||
|
|
Loading…
Reference in New Issue