> For the complete documentation index, see [llms.txt](https://tools.galois.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tools.galois.com/c2rust/c2rust.md).

# C2Rust

## From C to Rust, to Better Rust

Many of the most important systems in the world are written in inherently unsafe languages such as C, the memory-related vulnerabilities of which expose a significant attack surface for hackers. It would be beneficial to rewrite these languages in safe-by-design languages, such as Rust, but migration of a real system by hand is enormously expensive and time consuming.&#x20;

This is why, for more than a decade, [Galois](http://galois.com) and [Immunant](https://immunant.com/) have been developing **C2Rust, our automatic migration tool that is able to translate most C modules into semantically equivalent** [**Rust**](https://www.rust-lang.org/) **code.** &#x20;

*Click the link below to try C2Rust for yourself!*

<table data-view="cards" data-full-width="false"><thead><tr><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td>C2Rust Demonstration <mark style="color:yellow;">→</mark></td><td><a href="https://c2rust.com">https://c2rust.com</a></td></tr></tbody></table>

<figure><img src="https://1144426975-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F11xJ6TZLGSMeaKYNw788%2Fuploads%2FmaJ5hHlxgi3v2Tn7qdY1%2FC2Rust%20Logo1.png?alt=media&amp;token=6ce9a27b-3a8a-4f55-9fef-14e7508f72e2" alt=""><figcaption></figcaption></figure>

Our original C2Rust transformed C code into unsafe, C-like Rust code. This is the first step of migration, but ultimately, we want Rust that is safe, performant, and idiomatic.&#x20;

The current state of the art is to run C2Rust, and then for an expert team to migrate the rest of the way. Immunant have done exactly this on the migration of the dav1d codec library to Rust. The next step, currently in active development, is to create an automated migration tool that can fully transform C code to safe, performant Rust.&#x20;

Even as the C2Rust continues to improve, it is already being widely used — for example, the popular serde\_yaml crate is just a wrapper around c2rust-transpiled code. No matter your current tech stack, there are effective ways to integrate C2Rust into your workflow.&#x20;

This project is available under the [BSD-3 license](https://github.com/immunant/c2rust/blob/master/LICENSE).

## Download C2Rust

Source code and instructions are available in our [git repository](https://github.com/immunant/c2rust).

## Contact

To report issues with the translation or tool, please use our [Issue Tracker <mark style="color:yellow;">→</mark>](https://github.com/immunant/c2rust/issues)

For more information, email us at [info@c2rust.com <mark style="color:yellow;">→</mark>](mailto:info@c2rust.com)

***

<figure><img src="https://1144426975-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F11xJ6TZLGSMeaKYNw788%2Fuploads%2F5rixZWVvHEBJVSrRcDK6%2FUntitled%20(600%20x%20100%20px).png?alt=media&amp;token=d1a05196-5082-4a83-9d14-a7845ae29ac4" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://tools.galois.com/c2rust/c2rust.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
