VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
villagesql crate. The SDK handles all FFI marshaling — you write ordinary Rust, and the extension! macro generates the C entry points the server calls at load time.
When to Choose Rust
Rust is the right choice when:- You prefer Rust and don’t need a C++ codebase
- You want memory safety without a garbage collector
- You’re building a new extension and have no existing C++ dependency
Prerequisites
You need:- Rust stable toolchain — install at rustup.rs
- cargo-vsql — the Cargo subcommand for packaging, installing, and testing
cargo-vsql from the SDK repo:
Set Up a New Crate
Create a library crate and configure it:Cargo.toml:
manifest.json alongside Cargo.toml:
Write a Function
The Building Extensions in Rust page has the full walkthrough with the ROT-13 example. The short version: implementfn(&[InValue]) -> VdfReturn, register it with func!, and wrap everything in extension!:
Test Your Extension
Write a test inmysql-test/t/basic.test:
[ pass ] for each test file.
Install in SQL
Package and install:See also
- Building Extensions in Rust — full walkthrough with the ROT-13 example, packaging, and testing details
- Custom Types in Rust — define new column types with binary storage and ordering
- Rust API Reference — InValue, VdfReturn, and all macros
- Writing C++ Extensions — the C++ path for the same task

