Standard library
Find the module for a task and learn a few everyday utilities.
On this page
Standard-library namespaces are imported with use valk.name. Core types such as String, Array, Map, and ByteBuffer are available without importing a separate module in ordinary programs.
Find the right module#
| Task | Namespace or type | Guide |
|---|---|---|
| Text, lists, maps | String, Array, Map |
Strings & collections |
| Files and paths | valk.fs |
Files & streams |
| Reader/writer interfaces | valk.io |
Streams |
| JSON conversion | valk.json |
Working with JSON |
| HTTP clients and servers | valk.http |
HTTP & networking |
| TCP connections | valk.net |
Networking |
| Runtime templates | valk.template |
HTML templates |
| Threads and worker results | valk.thread |
Concurrency |
| Dates, clocks, sleeping | valk.time |
Examples below |
| Hashes and random bytes | valk.crypto |
Example below |
The API reference lists public declarations and signatures. These guides explain common workflows; use the reference when you need the full set of options on a particular type.
Work with a UTC date#
use valk.time
fn main() {
let date = time.DateTime.new(2026, 1, 15, 9, 30, 0, 0) ! {
println("Invalid date")
return
}
let tomorrow = date.add_days(1) ! {
println("Date is outside the supported range")
return
}
println(date.format("Y-m-d")) // 2026-01-15
println(tomorrow.format("Y-m-d")) // 2026-01-16
}
DateTime uses UTC. add_* and with_* methods return a new date; methods beginning with modify_ change the existing object. Invalid dates produce an error. DateTime.now() returns the current time, and to_iso8601() produces an ISO-formatted string.
For elapsed durations, use a monotonic clock such as time.mono_ms() instead of comparing wall-clock dates. A monotonic clock is intended for measuring elapsed time even when the system's wall clock changes.
Hash text#
use valk.crypto
fn main() {
let digest = crypto.sha256_encode("Valk")
println(digest)
}
sha256_encode produces a hexadecimal SHA-256 digest. Use the operation appropriate to the data: a fast content hash is different from password hashing, for which the library provides bcrypt_hash and bcrypt_verify. crypto.random_bytes(length) supplies random bytes for applications that need them.
Build output in memory#
ByteBuffer is useful when producing text or bytes in several steps:
fn main() {
let output = ByteBuffer.new()
output.write("Total: ")
output.write_f64_ascii(12.5, 2)
println(output.to_string()) // Total: 12.50
}
Use text-writing methods for human-readable output and endian-specific binary methods for binary formats. A ByteBuffer also implements io.Writer, so code written against that interface can target memory as well as a file or connection.