json
JSON Parse & Manipulate
Parse, build, and edit JSON. Backed by serde_json in Rust, nested get/set, merge, and pretty-print included.
- parse & stringify
- Dot-path access
- Deep merge
- Pretty-print
File & Path I/O
Core Standard Library
io covers filesystem work: slurp a small config, stream a big log file line by line, join path segments without worrying about slashes on Windows vs Linux.
Whole-file helpers are fine for kilobyte-scale files. For anything large, open a handle and read chunks. If disk I/O would stall the VM, dispatch it to a background thread and poll when it's done. Errors come back as structured objects with a code and message, not opaque strings.
Import
import "io" |
Quick start
import "io" |
|
let content = io.read_file("config.toml") |
io.write_file("out/result.txt", content) |
let path = io.join("data", "logs", "app.log") |
High-level overview of what io is for.
read_file and write_file when the whole thing fits in memory, configs, small exports, generated reports.
Open once, read or write incrementally. Use this for log tailing and datasets that won't fit in RAM.
Move blocking reads/writes off the main thread and check back when they finish.
join, dirname, basename, extension, is_absolute, exists, the usual path helpers, cross-platform.
Failed opens and permission denials return typed errors you can match on instead of parsing strings.
54 functions and methods in io. Grouped by category from the standard library docs.
| Signature | Description |
|---|---|
| io_join(a, b, …) | Join path segments (`PathBuf::push`) |
| io_join_many(parts) | Join an array of segments; empty array → `""` |
| io_dirname(path) | Parent directory; root → `"."` |
| io_basename(path) | Final path component |
| io_stem(path) | File name without extension |
| io_extension(path) | Extension without dot, or `""` |
| io_is_absolute(path) | Whether path is absolute |
| io_canonical(path) | Resolve to absolute canonical path |
| Signature | Description |
|---|---|
| io_exists(path) | Path exists (any type) |
| io_is_file(path) | Regular file |
| io_is_dir(path) | Directory |
| io_is_symlink(path) | Symbolic link |
| io_file_size(path) | Size in bytes |
| io_modified_ms(path) | Last modified time (Unix ms) |
| io_created_ms(path) | Creation time (Unix ms); may fail on some platforms |
| Signature | Description |
|---|---|
| io_read_file(path) | Read entire file as UTF-8 text |
| io_read_bytes(path) | Read raw bytes as `int_array` (0–255 per element) |
| io_write_file(path, text) | Create/truncate and write text |
| io_write_bytes(path, bytes) | Write raw bytes |
| io_append_file(path, text) | Append text (creates file if needed) |
| io_read_lines(path) | Split into lines; newlines stripped |
| io_write_lines(path, lines) | Write lines joined with `\n` (no trailing newline after last line) |
| Signature | Description |
|---|---|
| io_list_dir(path) | Immediate children (sorted names) |
| io_list_dir_recursive(path) | All files/dirs under `path` (relative paths; dirs end with `/`) |
| io_create_dir(path) | Create single directory |
| io_create_dir_all(path) | Create directory tree |
| io_remove_file(path) | Delete a file |
| io_remove_dir(path) | Remove empty directory |
| io_remove_dir_all(path) | Remove directory tree |
| io_copy(src, dst) | Copy file |
| io_rename(src, dst) | Rename or move |
| Signature | Description |
|---|---|
| io_cwd() | Current working directory |
| io_chdir(path) | Change working directory |
| io_temp_dir() | OS temp directory |
| io_home_dir() | User home (`HOME` / `USERPROFILE`) |
| Signature | Description |
|---|---|
| io_open(path, mode) | Open file; returns handle id |
| io_close(handle) | Flush and close |
| io_read(handle, n) | Read up to `n` bytes |
| io_read_all(handle) | Read remainder |
| io_read_line(handle) | One line (text only); `nil` at EOF |
| io_write(handle, data) | Bytes/chars written |
| io_flush(handle) | Flush buffers |
| io_seek(handle, offset, whence) | Seek; returns new position |
| io_tell(handle) | Current position |
| io_eof(handle) | Whether EOF was reached on last read |
| Signature | Description |
|---|---|
| io_async_read(path) | Background read text |
| io_async_read_bytes(path) | Background read bytes |
| io_async_write(path, text) | Background write text |
| io_async_write_bytes(path, bytes) | Background write bytes |
| io_async_copy(src, dst) | Background file copy |
| io_task_done(task) | `true` when finished or cancelled |
| io_task_poll(task) | Result if done; `nil` if pending |
| io_task_wait(task) | Block until done, then return result |
| io_task_cancel(task) | Cancel pending task; `true` if cancelled |
More from Core Standard Library.
JSON Parse & Manipulate
Parse, build, and edit JSON. Backed by serde_json in Rust, nested get/set, merge, and pretty-print included.
Wall-Clock & Time Zones
Timestamps, formatting, parsing, and time zones. Built on chrono and chrono-tz, DST handled correctly.
Regular Expressions
Regular expressions via Rust's regex crate. Match, split, replace, and compile patterns once for hot loops.