diff --git a/doc/docs.md b/doc/docs.md index 701d9874a5..f24ad62d8a 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -36,7 +36,7 @@ you can do in V. Match Structs - Short struct init syntax + Short struct init syntax Access modifiers Methods Pure functions by default @@ -683,6 +683,7 @@ struct ButtonConfig { width int = 70 height int = 20 } + fn new_button(c ButtonConfig) &Button { return &Button{ width: c.width @@ -694,6 +695,20 @@ fn new_button(c ButtonConfig) &Button { button := new_button(text:'Click me', width:100) // the height is unset, so it's 20, the default value ``` +As you can see, we can use + +``` +new_button(text:'Click me', width:100) +``` + +instead of + +``` +new_button(ButtonConfig{text:'Click me', width:100}) +``` + +This only works with functions that have a single struct argument. + ## Access modifiers Struct fields are private and immutable by default (making structs immutable as well).