Rust Usage

Usage Instructions for Rust

For examples of how to build a Rust program which compiles and runs on Valida, see lita-xyz/rust-examples on Github. You can use any of these examples as a starting point for developing your own programs using the Valida toolchain. Here are steps for doing so:

  1. Clone the project template:

git clone https://github.com/lita-xyz/fibonacci.git
  1. cd into the project template:

cd fibonacci
  1. Enter the Valida shell or the Docker toolchain shell, following the instructions specific to your selected installation method.

  2. Build the project:

cargo +valida build
  1. Run the code:

valida run --fast target/valida-unknown-baremetal-gnu/debug/fibonacci log

The first requirement for Rust code for Valida is to annotate the entrypoint (main.rs) file with #![no_main] and follow the requirements for writing programs which do not use the standard library (see here for details). We also do not (yet) support a main function signature that takes any arguments. The following is a demonstration of a simple program that shows how the main function must be declared instead:

#![no_main]

valida_rs::entrypoint!main(main);

#[no_mangle]
fn main() {
    ...
}

If you do not require the pseudo-random number support included in the valida_rs crate, then you can omit line 3. Explicitly, here is how the main function may be declared in this case:

#![no_main]

#[no_mangle]
fn main() {
    ...
}

Rust library functions, etc.

See USAGE: Using the Rust toolchain for more information on how to write Rust programs to run on Valida.

Last updated