Skip to content

Commit

Permalink
doc: document new static type methods
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Jun 26, 2023
1 parent 21d9730 commit d52bac8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions doc/docs.md
Expand Up @@ -97,6 +97,7 @@ by using any of the following commands in a terminal:
* [Trailing struct literal arguments](#trailing-struct-literal-arguments)
* [Access modifiers](#access-modifiers)
* [Anonymous structs](#anonymous-structs)
* [Static type methods](#static-type-methods)
* [[noinit] structs](#noinit-structs)
* [Methods](#methods)
* [Embedded structs](#embedded-structs)
Expand Down Expand Up @@ -2431,6 +2432,19 @@ assert book.author.name == 'Samantha Black'
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

V supports `[noinit]` structs, which are structs that cannot be initialised outside the module
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/ast/str.v
Expand Up @@ -382,7 +382,7 @@ pub fn (x Expr) str() string {
return '${x.name}(${sargs})${propagate_suffix}'
}
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}'
}
Expand Down

0 comments on commit d52bac8

Please sign in to comment.