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
- 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)
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
- clone the repo and open in vscode
- If you don’t have an M1/M2 mac click the tooltip that shows up to start the devcontainer
- in the devcontainer terminal run `dfx start --background"
If you do have an M1 of M2 mac
- clone the repo and open in vscode and do not click the popup
- remove the .devcontainer directory
- make sure you have rust toolchain installed
- run `dfx start --background"
Changing the project name
To give the project your desired project name just run a find and replace on all instances of
your_project_name and change the name of the
starter directory and the
starter.did file to
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.