mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
doc: document json anonymous struct fields
This commit is contained in:
19
doc/docs.md
19
doc/docs.md
@ -2611,9 +2611,9 @@ For this reason V doesn't allow the modification of arguments with primitive typ
|
|||||||
Only more complex types such as arrays and maps may be modified.
|
Only more complex types such as arrays and maps may be modified.
|
||||||
|
|
||||||
### Variable number of arguments
|
### Variable number of arguments
|
||||||
V supports functions that receive an arbitrary, variable amounts of arguments, denoted with the
|
V supports functions that receive an arbitrary, variable amounts of arguments, denoted with the
|
||||||
`...` prefix.
|
`...` prefix.
|
||||||
Below, `a ...int` refers to an arbitrary amount of parameters that will be collected
|
Below, `a ...int` refers to an arbitrary amount of parameters that will be collected
|
||||||
into an array named `a`.
|
into an array named `a`.
|
||||||
|
|
||||||
```v
|
```v
|
||||||
@ -4303,6 +4303,9 @@ println(json.encode(data)) // {"x":42,"y":360}
|
|||||||
println(json.encode(user)) // {"name":"Pierre","score":1024}
|
println(json.encode(user)) // {"name":"Pierre","score":1024}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The json module also supports anonymous struct fields, which helps with complex JSON apis with lots
|
||||||
|
of levels.
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
### Asserts
|
### Asserts
|
||||||
@ -5866,25 +5869,25 @@ the boolean expression is highly improbable. In the JS backend, that does nothin
|
|||||||
|
|
||||||
### Memory usage optimization
|
### Memory usage optimization
|
||||||
|
|
||||||
V offers these attributes related to memory usage
|
V offers these attributes related to memory usage
|
||||||
that can be applied to a structure type: `[packed]` and `[minify]`.
|
that can be applied to a structure type: `[packed]` and `[minify]`.
|
||||||
These attributes affect memory layout of a structure, potentially leading to reduced
|
These attributes affect memory layout of a structure, potentially leading to reduced
|
||||||
cache/memory usage and improved performance.
|
cache/memory usage and improved performance.
|
||||||
|
|
||||||
#### `[packed]`
|
#### `[packed]`
|
||||||
|
|
||||||
The `[packed]` attribute can be added to a structure to create an unaligned memory layout,
|
The `[packed]` attribute can be added to a structure to create an unaligned memory layout,
|
||||||
which decreases the overall memory footprint of the structure.
|
which decreases the overall memory footprint of the structure.
|
||||||
|
|
||||||
> **Note**
|
> **Note**
|
||||||
> Using the [packed] attribute may negatively impact performance
|
> Using the [packed] attribute may negatively impact performance
|
||||||
> or even be prohibited on certain CPU architectures.
|
> or even be prohibited on certain CPU architectures.
|
||||||
> Only use this attribute if minimizing memory usage is crucial for your program
|
> Only use this attribute if minimizing memory usage is crucial for your program
|
||||||
> and you're willing to sacrifice performance.
|
> and you're willing to sacrifice performance.
|
||||||
|
|
||||||
#### `[minify]`
|
#### `[minify]`
|
||||||
|
|
||||||
The `[minify]` attribute can be added to a struct, allowing the compiler to reorder the fields
|
The `[minify]` attribute can be added to a struct, allowing the compiler to reorder the fields
|
||||||
in a way that minimizes internal gaps while maintaining alignment.
|
in a way that minimizes internal gaps while maintaining alignment.
|
||||||
|
|
||||||
> **Note**
|
> **Note**
|
||||||
|
Reference in New Issue
Block a user