Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,18 @@ You can find the slides [here](./slides/slides.md)
* [Rustlings](https://rustlings.rust-lang.org/)
* [Rustinfinity](https://www.rustfinity.com/)
* [The Rust Book Experiment](https://rust-book.cs.brown.edu/)

## Running the files

Before attempting to run the Rust files in this repo, ensure that you already [installed Rust for your operating system](https://www.rust-lang.org/tools/install) and have at least `cargo` or `rustc` available on your path (system or user).

To run the files in this course, navigate to the directory of the particular lesson and run the `cargo run` command. An example is shown below:

```sh
cd day-1/rust-basics
cargo run
```

If you wish to build a binary which you can run at a later time, you can use the `cargo build --release` command for an optimized release or the `cargo build` for an unoptimized release (debug release).

If you'd rather not navigate into directories to run files, you can utilize the `runfiles.sh` script on the root directory. It gives you an overview of all the `main.rs` files in the course and allows you run them iteractively. It uses `rustc` which Cargo also uses under the hood.
37 changes: 37 additions & 0 deletions runfiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

function rust_run(){
filepath=$(mktemp /tmp/mainXXXXXX)
rustc "$1" -o "$filepath"
"$filepath"
rm "$filepath"
}


shopt -s globstar

declare -A file_paths

echo "Available files"
rust_files=(day*/**/main.rs)
for index in "${!rust_files[@]}"; do
echo "$((index+1)). ${rust_files[$index]}"
done


echo -e "\n"

max_index=${#rust_files[@]}

while true; do
read -p "Which file do you want to execute (1 - $max_index): " file_index_to_execute

if [[ $file_index_to_execute =~ ^[0-9]+$ ]] && (( file_index_to_execute >= 1 && file_index_to_execute <= max_index )); then
rust_run "${rust_files[$((file_index_to_execute - 1))]}"
break
else
echo "Invalid input. Please enter a number between 1 and $max_index."
fi
done