examples/ in vsql-rust-sdk
vsql_rot13 — Function-Only Extension
The simplest possible Rust extension: one VDF that takes a STRING and returns a STRING. Usage:Directory Structure
Implementation
File:src/lib.rs
- VDFs receive
&[InValue]and returnVdfReturn— both are safe Rust enums - NULL is a first-class variant on both sides; pattern-match it directly
- The
extension!macro generates the C entry points the server calls at load time func!declares the SQL signature; argument and return types usevillagesql::Type::*
Manifest
File:manifest.json
vsql_rational — Custom Type with Arithmetic
A complete custom type: rational numbers stored as(numerator, denominator) in reduced form, with arithmetic functions, ordering, and hashing.
Usage:
Binary Storage Format
rational stores 16 bytes (little-endian):
- Bytes 0–7: numerator (
i64) - Bytes 8–15: denominator (
i64)
Type-System Functions
File:src/lib.rs
The type registers four operations: encode (string → bytes), decode (bytes → string), compare (for ORDER BY), and hash (for indexing).
VDF Implementations
VDFs that take a custom type receiveInValue::Custom(&[u8]) and decode the bytes themselves:
Registration
Theextension! macro registers both the type and its functions in a single declaration:
villagesql::custom!("name")references a custom type as an argument or returncustom_type!registers the type alongside its encode/decode/compare/hash functionsdefault: "0/1"is the intrinsic default — the server callsencode()on this string at type initialization, so it must be a valid valuepersisted_lengthmust match the byte lengthencode()returnsdeterministic: truelets the optimizer fold constant calls
Key Implementation Patterns
Testing
Both examples use MTR (the MySQL Test Runner) just like C++ extensions:--record.
Next Steps
Creating Extensions in Rust
SDK installation, build, and the extension! macro
Rust Custom Types
Deep dive on encode, decode, compare, and hash
Rust API Reference
InValue, VdfReturn, and the macro surface
Example Source
vsql_rot13 and vsql_rational complete source

