v2 / vlib / v / tests / modules / private_mutability / private_mutability.v
28 lines · 22 sloc · 456 bytes · c66fabc24faa148e21b7cf8de74a145609334288
Raw
1module private_mutability
2
3pub struct Counter {
4mut:
5 hidden int
6pub:
7 label string
8}
9
10fn increment_hidden(mut counter Counter) {
11 counter.hidden++
12}
13
14fn (mut counter Counter) bump_hidden() {
15 counter.hidden++
16}
17
18pub fn (mut counter Counter) bump_hidden_via_method() {
19 counter.bump_hidden()
20}
21
22pub fn (mut counter Counter) bump_hidden_via_helper() {
23 increment_hidden(mut counter)
24}
25
26pub fn (counter Counter) label_text() string {
27 return counter.label
28}
29