2 unstable releases

Uses new Rust 2024

0.2.0 Oct 23, 2025
0.1.3 Oct 10, 2025

#518 in Configuration

Download history 173/week @ 2025-10-08 16/week @ 2025-10-15 359/week @ 2025-10-22 504/week @ 2025-10-29 501/week @ 2025-11-05 591/week @ 2025-11-12 746/week @ 2025-11-19 877/week @ 2025-11-26 621/week @ 2025-12-03 554/week @ 2025-12-10

2,906 downloads per month

Apache-2.0

4MB
77K SLoC

C++ 60K SLoC // 0.2% comments Python 14K SLoC // 0.3% comments Rust 1K SLoC // 0.0% comments Bazel 1K SLoC // 0.2% comments TypeScript 865 SLoC // 0.3% comments Shell 377 SLoC // 0.2% comments CUDA 237 SLoC // 0.1% comments Batch 72 SLoC // 0.1% comments C 40 SLoC // 0.0% comments JavaScript 29 SLoC PowerShell 25 SLoC

xgrammar-rs

CI Deploy Docs

This project provides safe and idiomatic Rust bindings for the xgrammar C++ library. By wrapping the C++ implementation, this crate leverages Rust's memory safety andguarantees while providing access to xgrammar's high-performance and features for constraint decoding.

Prerequisites

Before building the project, ensure you have the following dependencies installed:

  • Rust toolchain: Install via rustup.
  • CMake: Required to build the underlying C++ xgrammar library.
  • C++ compiler: A modern C++ compiler that supports C++17 (Clang is hightly recommended.)

Build

The C++ xgrammar library is included as a submodule and will be compiled automatically as part of the build process.

To build the project, run the following command:

cargo build --release

This will create a release build in the target/release directory.

Test

This project uses cargo-nextest for running tests. To execute all tests, run:

make test

You can also pass arguments to cargo nextest via the TEST_ARGS variable. For example, to run a specific test suite:

make test TEST_ARGS="--test test_grammar"

Dependencies

~24–44MB
~654K SLoC