Skip to content

Commit 19d894d

Browse files
committed
doc: document new features in V and Veb
1 parent 4118ee4 commit 19d894d

2 files changed

Lines changed: 65 additions & 8 deletions

File tree

‎doc/docs.md‎

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ If V is already installed on a machine, it can be upgraded to its latest version
5454
by using the V's built-in self-updater.
5555
To do so, run the command `v up`.
5656

57+
## Project-local compiler versions with `.vvmrc`
58+
59+
If a project contains a `.vvmrc` file, commands like `v run .`, `v run file.v`,
60+
or `v file.v` will try to find and delegate to the requested V compiler version.
61+
This makes it easier to keep a project pinned to a known compiler release.
62+
63+
The file should contain one version per project, for example:
64+
65+
```text
66+
0.4.12
67+
```
68+
69+
Both `0.4.12` and `v0.4.12` are accepted. The special aliases `latest` and
70+
`current` keep using the currently running compiler.
71+
72+
V searches for `.vvmrc` from the target path upward and stops at repository and
73+
project boundaries such as `.git`, `.hg`, `.svn`, and `.v.mod.stop`.
74+
5775
## Packaging V for distribution
5876
See the [notes on how to prepare a package for V](packaging_v_for_distributions.md) .
5977

@@ -487,6 +505,10 @@ fn main() {
487505
}
488506
```
489507

508+
The compiler also warns about obviously constant conditions, for example
509+
self-comparisons like `if x == x { ... }` or `match` branches that can never be
510+
reached. These warnings help catch redundant checks and dead branches early.
511+
490512
To ignore values returned by a function `_` can be used
491513
```v
492514
fn foo() (int, int) {
@@ -3624,12 +3646,12 @@ To define a new type `NewType` as an alias for `ExistingType`,
36243646
do `type NewType = ExistingType`.<br/>
36253647
This is a special case of a [sum type](#sum-types) declaration.
36263648

3627-
Numeric aliases can use empty literal syntax for zero/default initialization:
3649+
Numeric aliases use ordinary conversions for initialization:
36283650

36293651
```v
36303652
type Decimal = f64
36313653
3632-
amount := Decimal{}
3654+
amount := Decimal(0.0)
36333655
```
36343656

36353657
### Enums
@@ -4219,6 +4241,23 @@ if mut w is Mars {
42194241

42204242
Otherwise `w` would keep its original type.
42214243
> This works for both simple variables and complex expressions like `user.name`
4244+
> and `values[i]`.
4245+
4246+
Smart casts also work on indexed expressions in `match` branches:
4247+
4248+
```v oksyntax
4249+
type Entry = int | string
4250+
4251+
values := [Entry('v')]
4252+
match values[0] {
4253+
string {
4254+
assert values[0] == 'v'
4255+
}
4256+
else {
4257+
assert false
4258+
}
4259+
}
4260+
```
42224261

42234262
#### Matching sum types
42244263

@@ -4336,7 +4375,7 @@ fn main() {
43364375
Trailing option-typed parameters can also be omitted in function calls.
43374376
When they are not passed, V supplies `none`:
43384377

4339-
```v
4378+
```v ignore
43404379
fn connect(url string, timeout ?int) {
43414380
actual_timeout := timeout or { 1000 }
43424381
println('${url} -> ${actual_timeout}')

‎vlib/veb/README.md‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ features.
88
- **Very fast** performance of C on the web.
99
- **Templates are precompiled** all errors are visible at compilation time, not at runtime.
1010
- **Middleware** functionality similar to other big frameworks.
11+
- **HTTPS support** directly from `veb` via `mbedtls`.
12+
- **Method-aware route middleware** for protecting only selected HTTP verbs.
13+
- **Static compression** with gzip/zstd, including manual pre-compression support.
1114
- **Controllers** to split up your apps logic.
15+
- **Graceful shutdown** support in the `new_veb` backend.
1216
- **Easy to deploy** just one binary file that also includes all templates. No need to install any
1317
dependencies.
1418

@@ -119,6 +123,18 @@ fn main() {
119123
}
120124
```
121125

126+
## Graceful shutdown
127+
128+
When running with `-d new_veb`, the underlying server supports graceful
129+
shutdown. Once shutdown begins, it stops accepting new requests, waits for
130+
in-flight requests to finish, and only then exits. This is useful for deploys,
131+
tests, and management endpoints that trigger a stop after sending a response.
132+
133+
The lifecycle controls come from the underlying `fasthttp.ServerHandle`
134+
(`wait_till_running()` and `shutdown(timeout: ...)`). If you need explicit
135+
server lifecycle management, use those lower-level hooks in the process that
136+
starts your app.
137+
122138
## Defining endpoints
123139

124140
To add endpoints to your web server, you must extend the `App` struct.
@@ -469,8 +485,8 @@ over gzip when the client supports both.
469485
1. **Manual pre-compression**: If you create `.zst` or `.gz` files manually, veb will serve
470486
them in zero-copy streaming mode for maximum performance when the MIME type is allowed.
471487
2. **Lazy compression cache**: Files smaller than the threshold are automatically compressed
472-
on first request and cached as `.zst` or `.gz` files on disk (zstd preferred when client
473-
supports it).
488+
on first request and cached under `os.cache_dir()/veb/static_compression/`
489+
(zstd preferred when the client supports it). The source directory stays unchanged.
474490
3. **Cache validation**: If the original file is modified, the compressed cache is
475491
automatically regenerated on the next request.
476492
4. **Streaming for large files**: Files larger than the threshold are served uncompressed in
@@ -561,8 +577,8 @@ curl -H "Accept-Encoding: zstd, gzip" --compressed http://localhost:8080/app.js
561577
# Request without encoding - should return uncompressed content
562578
curl -i http://localhost:8080/app.js
563579

564-
# Verify that compressed cache file was created
565-
ls -lh static/app.js.zst static/app.js.gz 2>/dev/null
580+
# Auto-generated cache files are stored under:
581+
# os.cache_dir()/veb/static_compression/
566582

567583
# Test manual pre-compression - style.css.zst is served directly (zero-copy)
568584
curl -H "Accept-Encoding: zstd" -i http://localhost:8080/style.css
@@ -579,6 +595,8 @@ serve `.zst` if the client supports zstd, otherwise `.gz` if gzip is supported.
579595

580596
- The lazy cache is created on first request, so the first visitor pays a small
581597
compression cost, but all subsequent requests are served at zero-copy speed.
598+
- Auto-generated cache files live in the OS cache directory, so read-only static
599+
folders still work and your source tree stays clean.
582600
- Large files (> threshold) are always streamed, ensuring low memory usage even for large assets.
583601
- The `encode_auto` middleware automatically chooses zstd or gzip based on client support. You can
584602
also use `encode_zstd` or `encode_gzip` for specific compression.
@@ -1165,4 +1183,4 @@ fn main() {
11651183
mut app := &App{}
11661184
veb.run[App, Context](mut app, 8080)
11671185
}
1168-
```
1186+
```

0 commit comments

Comments
 (0)