From 8d0fe3894a6a8dd839263bb2eaafc9c641567d1d Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 14 Jul 2022 11:06:10 +0300 Subject: [PATCH] doc: document anonymous structs --- doc/docs.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/doc/docs.md b/doc/docs.md index 45514ccbd0..9af4cd2903 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -2130,6 +2130,30 @@ Private fields are available only inside the same [module](#modules), any attemp to directly access them from another module will cause an error during compilation. Public immutable fields are readonly everywhere. +### Anonymous structs + +V supports anonymous structs: structs that don't have to be declared separately +with a struct name. + +``` +struct Book { + author struct { + name string + age int + } + title string +} + +book := Book{ + author: struct { + name: 'Samantha Black' + age: 24 + } +} +assert book.author.name == 'Samantha Black' +assert book.author.age == 24 +``` + ### Methods ```v