Skip to main content

Rust

Beginner
Rust

Rust is a fast, reliable, and safe programming language with a large, active developer community. To build ICP applications in Rust, you can use the Rust canister development kit (CDK). A CDK interfaces with the IC SDK to provide a programming language with functionalities for creating, deploying, calling, and managing canisters.

The Rust CDK and other Rust crates provide support for the full suite of ICP features, including HTTP certification, composite queries, and query stats, while other CDKs may have limited support for some advanced features.

Most developers use the IC SDK to build Rust canisters; however, experienced developers can opt to bypass the SDK and work directly with the Rust CDK for more fine-grained control.

The Rust CDK includes the following crates:

  • ic-cdk: Core methods that enable Rust programs to interact with the ICP system API.

  • ic-cdk-macros: Defines the procedural macros (e.g., update, query, import) that facilitate building operation endpoints and APIs.

  • ic-cdk-timers: Provides an API to schedule timers and periodic tasks.

Other crates for specific features exist, such as ic-stable-structures and ic-certification.

How to get started with Rust

To start building ICP dapps with Rust, you will need to either open a project in ICP Ninja or setup a local environment:

  1. Install Rust.

  2. Install the IC SDK.

  3. Create a new Rust project (dfx new my_project --type=rust) or download an example.

Rust example projects

There are several Rust example projects available for you to get started with or use as inspiration for your dapp.

The web IDE tool, ICP Ninja offers several template projects that can be edited and deployed directly from your web browser.

If you'd like to develop in a local environment, you can download the examples repo and navigate to the Rust subdirectory.

Rust documentation

The Rust CDK documentation can be found on crates.io.

The following documentation pages detail specific Rust workflows, best practices, and considerations: