Skip to content

Template Manual

This guide walks you through common development tasks—from getting started to advanced optimization—with links to detailed documentation as needed.

Prerequisites

Install Rust

If you don't have Rust installed, follow the instructions for your operating system

Download and run the installer from rustup.rs.

Alternatively, install via Chocolatey or Scoop:

choco install rust  # Chocolatey
scoop install rustup  # Scoop

Run the installer script:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Code Editor Setup

VSCode

Install these recommended extensions:

VSCode will prompt you to install these when you open the project, or install manually via the Extensions panel (Ctrl+Shift+X).

What are you editing?

Choose what you want to work on:

Editing Code

Open the src folder in your code editor for source development.

For CLI users: All commands below assume you're in the src directory.

How to Build

Using VSCode:

Press Ctrl+Shift+B to open the build task menu. Select rust: cargo build.

From Command Line:

cd src
cargo build  # for debug builds
cargo build --release  # for optimized release builds

How to Run

Using VSCode:

While in a Rust file, press F5 or click the "Run and Debug" button to execute your project with debugging enabled.

Not seeing Rust-specific options?

If prompted with a list of languages/technologies, select CodeLLDB.

From Command Line:

cd src
cargo run  # run debug build
cargo run --release  # run optimized release build

How to Debug

If using VSCode:

Install the CodeLLDB extension for native debugging support. Debug profiles are automatically created when the extension is installed.

VSCode Debugging

Debugging Rust applications with CodeLLDB in VSCode

For more info, see VSCode Integration

How to Test

Using VSCode:

Access pre-configured testing tasks via Ctrl+Shift+P → "Run Task":

  • Auto Test on Save - Automatically run tests when files change

Run Task

Access tasks via Ctrl+Shift+P → "Run Task"

Available Tasks

Pre-configured development tasks for testing and coverage

From Command Line:

cd src
cargo test  # run all tests

When you push code, GitHub Actions automatically runs tests on Linux, Windows, and macOS—check the "Actions" tab to see results.

PR Checks

For more info, see Automated Testing & Publishing

How to Lint

What is linting?

Linting automatically checks your code for common mistakes, style issues, and potential bugs.
It's like a spell-checker for code that catches problems before you run your program.

Using VSCode:

Linting runs automatically in VSCode with the rust-analyzer extension. You'll see warnings and suggestions directly in your editor as you type.

Clippy Linting

Clippy integration provides advanced linting out of the box

From Command Line:

cd src
cargo clippy  # run linter checks

Clippy will show warnings and suggestions to improve your code quality.

How to Check Coverage

What is coverage?

Coverage shows which parts of your code are tested (green) and which aren't (red).
This helps you find gaps in your tests and improve code quality.

Using VSCode:

Access pre-configured coverage tasks via Ctrl+Shift+P → "Run Task":

  • Auto Coverage on Save - Automatically generate coverage reports when files change

Run Coverage Task

Run "Auto Coverage on Save" task via Ctrl+Shift+P → "Run Task"

You can preview coverage in the IDE directly with 'Coverage Gutters':

  • Coverage Gutters: Preview Coverage Report - View HTML coverage report in browser

Preview Coverage Report

Preview coverage report via Ctrl+Shift+P → "Coverage Gutters: Preview Coverage Report"

  • Coverage Gutters: Watch - Live coverage visualization in editor (shows green/red lines)

Coverage Gutters

Coverage show covered (green) and uncovered (red) lines in editor.
Activate with Ctrl+Shift+PCoverage Gutter: Watch

When you push code, use the Codecov dashboard (click the coverage badge in your README) to track coverage trends and find untested code:

Codecov Dashboard

Coverage Pills

For more info, see Automated Testing & Publishing

How to Check for Unsafe Code Issues and Undefined Behaviour

What is Miri?

Miri detects memory bugs and undefined behaviour that normal tests miss.
Critical for mission-critical applications, low-level code, and projects using unsafe blocks.
Examples: out-of-bounds access, misaligned memory, arithmetic overflow.

Using VSCode:

Press Ctrl+Shift+P → "Run Task" → Select Run Tests to Detect Undefined Behaviour to run Miri tests.

From Command Line:

First install Miri (one-time setup):

rustup +nightly component add miri

Run Miri tests in your project:

cd src
cargo +nightly miri test

# Run a single test
cargo +nightly miri test test_name

Miri is MUCH slower than normal tests

This is expected—Miri thoroughly checks every memory operation. Use it primarily for projects with unsafe code, FFI bindings, or mission-critical applications.

For more info, see Miri Testing

How to Benchmark

What is benchmarking?

Benchmarking measures how fast your code runs.
Helps you track performance improvements and compare different implementations.

Run benchmarks:

cd src
cargo bench  # run all benchmarks

This generates detailed HTML reports in target/criterion/report/index.html.

Benchmark CLI Output

CLI output when running benchmarks

Benchmark Report

Example generated HTML report showing performance trends

Benchmark Comparison

Violin plot comparing different files or implementations

Add benchmarks:

Create benchmark modules in benches/ directory. Example structure:

benches/
├── main.rs          # Entry point
└── my_bench.rs      # Your benchmarks

In main.rs:

mod my_bench;
use criterion::{criterion_group, criterion_main, Criterion};
use my_bench::bench_my_function;

fn criterion_benchmark(c: &mut Criterion) {
    bench_my_function(c);
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

In my_bench.rs:

use criterion::Criterion;

pub fn bench_my_function(c: &mut Criterion) {
    c.bench_function("my_function", |b| {
        b.iter(|| {
            // Code to benchmark here
        })
    });
}

How to Profile

What is profiling?

Profiling identifies which parts of your code are slow (bottlenecks).
Use after benchmarking shows performance issues.

Install cargo-flamegraph globally (one-time setup):

cargo install cargo-flamegraph
# if on Linux, ensure `perf` and `objdump` are available/installed

Generate flamegraph:

cd src
cargo flamegraph --bench my_benchmark --profile profile -- --bench
cd src
# Requires administrator privileges - run in admin command prompt or with sudo
sudo cargo flamegraph --bench my_benchmark --profile profile -- --bench

Open the generated flamegraph.svg in your web browser to explore the interactive visualization.

Flamegraph Example

Interactive flamegraph showing function call hierarchy and time spent

Platform-specific tools:

After running the flamegraph command, a perf.data file will be created in your src/ directory.

Analyze it with perf report or Hotspot GUI:

perf report perf.data

Linux Perf CLI

Linux perf command-line analysis

Linux Hotspot

Hotspot GUI tool for visualizing perf profile data

Use Visual Studio Profiler for detailed analysis. First, build benchmarks:

cd src
cargo bench

Then in Visual Studio:

  1. Open Visual Studio → "Continue without code"

    Visual Studio Start

    Visual Studio start screen

  2. Select DebugPerformance Profiler

    Performance Profiler Menu

    Select Debug → Performance Profiler

  3. Choose Executable → Navigate to target/profile/deps/my_benchmark-....exe

    Select Executable

    Select the benchmark executable

    Navigate to Binary

    Navigate to target/profile/deps/

  4. Enable CPU Usage → Click Start

    Start Profiling

    Enable CPU Usage and start profiling

    Visual Studio Profiler

    Visual Studio 2022 Community Profiler showing CPU usage

How to Use Profile Guided Optimization (PGO)

What is PGO?

Profile Guided Optimization uses runtime statistics to make your code run faster.
The compiler learns how your code actually runs, then optimizes based on that data.

Install cargo-pgo globally (one-time setup):

cargo install cargo-pgo
rustup component add llvm-tools-preview

Use in your project:

cd src
cargo pgo instrument test  # collect profiling data
cargo bench  # establish baseline
cargo pgo optimize bench  # build with PGO and compare

cargo pgo info

Verify cargo-pgo installation with cargo pgo info

Benchmark CLI

Run baseline benchmark without PGO

cargo pgo optimize result

Results showing performance improvement from PGO

For more info, see Profile Guided Optimization

How to Build for Other Platforms

Why cross-compile?

Sometimes you want to build for other platforms, e.g. test Windows builds on Linux.
Cross-compilation lets you do this without switching operating systems.

Install globally (one-time setup):

cargo install cross --git https://github.com/cross-rs/cross

Use in your project:

cd src
cross build --target x86_64-pc-windows-gnu  # build for Windows
cross test --target aarch64-unknown-linux-gnu --release  # test for ARM64 Linux

The cross tool uses Docker or Podman containers to handle cross-compilation automatically. Simply replace cargo with cross and specify your target platform.

For more info, see Cross Compilation

How to Create C/C++ Bindings

Why create bindings?

Sometimes you may want to run your Rust code outside of Rust.
C/C++ bindings let you call your Rust functions from C, C++, or any language with C interop.

Export functions:

Use #[no_mangle] and extern "C" to make functions callable from C/C++:

#[no_mangle]
pub extern "C" fn add_numbers(a: i32, b: i32) -> i32 {
    a + b
}

Generate bindings:

Manual generation is only needed when adjusting configuration.

Headers are auto-generated in automated builds and published in releases.

Using VSCode, press Ctrl+Shift+P → "Run Task" → Select one of:

  • Generate C Bindings - Generate C headers only
  • Generate C++ Bindings - Generate C++ headers only

Or from command line:

cd src

# Install cbindgen (one-time setup)
cargo install cbindgen

# Generate C bindings
cbindgen --config ../.github/cbindgen_c.toml --output bindings/c/your-project.h your-project

# Generate C++ bindings
cbindgen --config ../.github/cbindgen_cpp.toml --output bindings/cpp/your-project.hpp your-project

Replace your-project with your actual project name. Configuration files are located in .github/:

  • .github/cbindgen_c.toml - C bindings configuration
  • .github/cbindgen_cpp.toml - C++ bindings configuration

C Bindings Releases

Headers automatically attached to GitHub releases

For more info, see C/C++ Bindings

In particular, check out the How to Export Functions section for useful patterns.

How to Create C# Bindings

Export functions:

C# bindings are autogenerated from C bindings

See the C/C++ Bindings section above for how to export functions with #[no_mangle] and extern "C".

Bindings are generated when you build into bindings/csharp/NativeMethods.g.cs. Customize generation in build.rs using csbindgen.

For more info, see C# Bindings

Editing Documentation

Documentation lives in the doc/ folder

It uses MkDocs for building static sites.

If using VSCode:

Open the doc/ folder in a new VSCode window (File → Open Folder) for formatting rules to apply.

Open a terminal and run:

python3 start_docs.py

Ctrl+click the http://localhost:8000 link in the terminal output to open the docs in your browser.

From Command Line:

To preview documentation locally:

cd doc
python3 start_docs.py

This starts a local server at http://localhost:8000 with live reload.

See doc/README.md for more information.

Contributing

Want to contribute?

Follow these guidelines to keep the project history clean and organized.
These practices make code review easier and help maintain project quality.
Not sure about something? Just ask—whether it's "is it okay to work on this?" or "how do I do this?"

One Change Per PR

Keep pull requests focused and atomic. Try to do one logical change per pull request rather than bundling multiple unrelated changes together.

Commit Names

When writing commit messages, follow the Keep a Changelog style to help maintain clear project history:

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Example commit messages:

Added support for async operations
Fixed memory leak in parser
Changed API parameter order (breaking change)

Miscellaneous

GitHub Workflows

The .github folder contains pre-configured issue templates, PR templates, and CI/CD workflows.

You may want to edit these to match your project's needs:

  • Issue templates - Located in .github/ISSUE_TEMPLATE/
  • Workflow files - Located in .github/workflows/

When you push code, these workflows automatically run tests on Linux, Windows, and macOS.

GitHub Template Selector

Template selector for bug reports and feature requests

Bug Report Template

Pre-configured bug report template with structured fields

For more info, see GitHub Templates