Alternative Rust canister starter repo

I created this alternative rust starter repo for myself hopefully it is useful to other as well!

From the Readme:


I often find myself making the same edits to the dfx new -type rust starter template. This alternative starter template contains the following:

  • Different directory structure without a frontend
  • Automatic Candid file generation if you run cargo test
  • A global State object using the thread_local pattern which is saved in stable memory across updates
  • An example of a update and query call
  • Updated release profile based on this great blog post about Effective Rust canisters
  • A devcontainer configuration so you can install the entire needed toolchain with a single click in vscode based on this tutorial (needs docker)

:warning: Sadly the devcontainer does not work on ARM macs. Please open an issue if you experience issues on other platforms as I couldn’t test those

Getting started

  1. clone the repo and open in vscode
  2. If you don’t have an M1/M2 mac click the tooltip that shows up to start the devcontainer
  3. in the devcontainer terminal run `dfx start --background"
  4. run dfx deploy

If you do have an M1 of M2 mac

  1. clone the repo and open in vscode and do not click the popup
  2. remove the .devcontainer directory
  3. make sure you have rust toolchain installed
  4. run `dfx start --background"
  5. run dfx deploy

Changing the project name

To give the project your desired project name just run a find and replace on all instances of starter to your_project_name and change the name of the starter directory and the starter.did file to your_project_name and your_project_name.did as well.

Final tip: You can additional fields to your structs accross upgrades if you wrap the new field values with the Option type. Otherwise you will get an error in the post_upgrade hook and the upgrade will fail.

Feel free to open up an issue if you’d like an example of different concepts as well.



Make sure to add it to Internet Computer Content Validation Bootstrap
See: GitHub - dfinity/portal: Internet Computer Developer Portal

Btw: I’m also (slowly) working on a total overhaul of GitHub - dfinity/awesome-icp: A curated list of awesome projects and resources relating to the Internet Computer Protocol to make these things even easier to discover.