1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

doc: document new static type methods

This commit is contained in:
Alexander Medvednikov 2023-06-27 01:31:48 +03:00
parent 21d9730cde
commit d52bac8ee9
2 changed files with 15 additions and 1 deletions

View File

@ -97,6 +97,7 @@ by using any of the following commands in a terminal:
* [Trailing struct literal arguments](#trailing-struct-literal-arguments) * [Trailing struct literal arguments](#trailing-struct-literal-arguments)
* [Access modifiers](#access-modifiers) * [Access modifiers](#access-modifiers)
* [Anonymous structs](#anonymous-structs) * [Anonymous structs](#anonymous-structs)
* [Static type methods](#static-type-methods)
* [[noinit] structs](#noinit-structs) * [[noinit] structs](#noinit-structs)
* [Methods](#methods) * [Methods](#methods)
* [Embedded structs](#embedded-structs) * [Embedded structs](#embedded-structs)
@ -2431,6 +2432,19 @@ assert book.author.name == 'Samantha Black'
assert book.author.age == 24 assert book.author.age == 24
``` ```
### Static type methods
V now supports static type methods like `User.new()`. These are defined on a struct via
`fn [Type name].[function name] and allow to organize all functions related to a struct:
```v oksyntax
struct User { }
fn User.new() User { return User{} }
user := User.new()
```
### `[noinit]` structs ### `[noinit]` structs
V supports `[noinit]` structs, which are structs that cannot be initialised outside the module V supports `[noinit]` structs, which are structs that cannot be initialised outside the module

View File

@ -382,7 +382,7 @@ pub fn (x Expr) str() string {
return '${x.name}(${sargs})${propagate_suffix}' return '${x.name}(${sargs})${propagate_suffix}'
} }
if x.name.contains('__static__') { if x.name.contains('__static__') {
return '${x.mod}.${x.name}(${sargs})${propagate_suffix}1' return '${x.mod}.${x.name}(${sargs})${propagate_suffix}'
} }
return '${x.mod}.${x.name}(${sargs})${propagate_suffix}' return '${x.mod}.${x.name}(${sargs})${propagate_suffix}'
} }