New to Rust? We recommend checking out Rust by
Example to get up to speed.
Local development
To run the code for your challenge locally, you’ll needcargo
installed. Our test runners use version 1.76
(as of April 2024).
The script for your challenge (like ./your_bittorrent.sh
) will automatically compile and run your code using cargo run
. It’ll
look something like this:
File structure
- The files for your solution are placed in the
src
directory. src/main.rs
contains themain
function, which is what the test runner executes.
Adding more files
You can add more files and directories to thesrc
directory. The test runner will include them when compiling your code.
Rust uses modules to organize code. For example, to define the foo
module, create a file at src/foo.rs
.
You can use functions and variables from foo.rs
in your main code like so:
Remember to make
foo()
accessible to main.rs
by adding the pub
identifierAdding dependencies
You can add dependencies to your program usingcargo add
.
For example, to add the rand
crate, run the following command:
rand
crate and add it to your Cargo.toml
file:
Cargo.lock
file.