From a66eebc651c05ac2b9d018c3e11d06dbec1a6c94 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 17 May 2020 16:15:02 +0200 Subject: [PATCH] doc: clarify the short struct syntax --- doc/docs.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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).