# Standard Library

> **Vex's standard library.** Prelude (auto-imported) plus explicitly imported packages.

For a practical learning sequence, start with
[your first standard-library workflow](stdlib-start.md), then return here
to distinguish prelude names from package imports.

## Prelude (Auto-Imported)

These are available everywhere without `import`:

### Collections
| Type | Description |
|-----|----------|
| `Vec<T>` | Dynamic array bound to its construction-time allocator region |
| `Map<K, V>` | Hash map (SwissTable) |
| `Set<T>` | Hash set |
| `string` | Owning string with inline storage for small values |
| `str` | Borrowed string view |

### Smart Pointers
| Type | Description |
|-----|----------|
| `Box<T>` | Compiler-managed heap ownership; sharing and thread safety are inferred automatically |
| `Ptr<T>` | Typed pointer |
| `Span<T>` | Non-owning pointer-and-length view; checked access does not validate its lifetime |
| `RawBuf` | Raw byte buffer |
| `Layout` | Checked allocation size and alignment |
| `Mem` | Canonical low-level allocation and byte-operation namespace |
| `Limits` | Target-aware compile-time integer minimum and maximum values |

### Error & Optionality
| Type | Description |
|-----|----------|
| `Result<T, E>` | Operations that can fail |
| `Option<T>` | Values that may not exist |
| `Range<T>` | Range expressions |
| `Complex<T>` | Complex numbers |

## Packages (Import Required)

Memory primitives are deliberately absent from this list: there is no
`std/mem` package. Low-level code uses the prelude `Mem.*` boundary; most code
uses owning types such as `Box`, `Vec`, or `string`.

Use each package's documented path, for example `import { File } from "fs";`.
A heading such as “standard library” is not an instruction to prepend `std/`
to every import. `Math`, `Bit`, and `Crypto` are builtin namespaces; they do
not require imports. The `crypto` package is distinct from the `Crypto`
builtin namespace.

Choose a package by the task and data ownership you need. Each linked guide
shows its imports, examples and specific input/output contracts.

| Area | Guide |
| --- | --- |
| Command-line programs | [CLI](../std/cli.md), [system](../std/sys.md), [logging](../std/log.md) |
| Data structures and ordering | [Collections](../std/collections.md), [sort](../std/sort.md), [filter](../std/filter.md) |
| Errors and cancellation | [Errors](../std/errors.md), [context](../std/context.md) |
| Files and paths | [File system](../std/fs/index.md) |
| Byte streams and compression | [I/O](../std/io.md), [compression](../std/compress/index.md) |
| Structured data | [Serde](../std/serde/index.md): JSON, TOML, YAML, CSV, CBOR and MessagePack |
| Text and parsing | [Strings](../std/strings.md), [strconv](../std/strconv.md), [Unicode](../std/unicode.md), [encoding](../std/encoding.md) |
| TCP and UDP | [Networking](../std/net.md) |
| Web protocols | [HTTP](../std/http/index.md), [URL](../std/url.md), [TLS](../std/tls.md), [WebRTC](../std/webrtc.md) |
| Regular expressions | [Regex](../std/regex/index.md) |
| Hashes, secrets and random values | [Hash](../std/hash.md), [crypto](../std/crypto/index.md), [randomness](../std/rand.md) |
| Database access | [Database](../std/db/index.md) |
| Time | [Time](../std/time/index.md) |
| Locations and routes | [Geo](../std/geo.md) |
| Images, video and audio | [Vips](../std/vips.md), [media](../std/media.md) |
| Numeric/model computation | [ML](../std/ml.md), [inference](../std/inference.md) |
| Version requirements | [Semver](../std/semver.md) |
| Reusable protocols and tests | [Contracts](../std/contracts.md), [testing](../std/testing.md) |
| Build language tools | [IDE packages](tooling/language-tools.md) |

The [standard library index](../std/index.md) lists the package families. Import paths
come from the individual module guides, including focused submodule imports
when a program needs only a parser, codec or transform.

## Compose packages around ownership

A file-processing command can parse arguments with `cli`, read bounded input
with `fs`, decode structured data with `serde`, sort records with `sort` and
write its result through `io`. Keep parse and I/O errors typed until the CLI
boundary. Use `context` when cancellation/deadline state must follow an operation.

For media work, `vips` operates on image pixels, `media` on explicit frame/audio
layouts, and `webrtc` on encoded packets and presentation timing. Conversion
between packages may copy into a new owner; it is not automatically a pointer
transfer. The image/media guides show that boundary directly.

## Next Steps

- [VUMM Memory Model](memory/vumm.md)
- [Error Handling](error-handling.md)
- [FFI](ffi.md)
