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

doc: update struct access modifiers (#13734)

This commit is contained in:
serg-meus 2022-03-14 23:38:36 +07:00 committed by GitHub
parent dbb18e3656
commit d6eb6d5bae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2084,29 +2084,9 @@ __global:
f int // public and mutable both inside and outside parent module f int // public and mutable both inside and outside parent module
} }
``` ```
Private fields are available only inside the same [module](#modules), any attempt
For example, here's the `string` type defined in the `builtin` module: to directly access them from another module will cause an error during compilation.
Public immutable fields are readonly everywhere.
```v ignore
struct string {
str &byte
pub:
len int
}
```
It's easy to see from this definition that `string` is an immutable type.
The byte pointer with the string data is not accessible outside `builtin` at all.
The `len` field is public, but immutable:
```v failcompile
fn main() {
str := 'hello'
len := str.len // OK
str.len++ // Compilation error
}
```
This means that defining public readonly fields is very easy in V.
### Methods ### Methods