vlang / rfcs

RFCs for changes to V

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[struct] set access modifier

igotfr opened this issue · comments

struct Sct {
set:
  n int
}

s := Sct{n: 5}
s.n = 7 // ok
println(s.n) // error

@spytheman a property that can't be accessed directly, only setted, but it's useful for calculations in methods with visible return (computed), similar to private, but of course, no inheritance

I know abstract motivation but I don't remember any real-world scenarios (I guess the best example is a password)

In V, specifically for properties we have:

mut get set
default get

with set, would be:

set set