RU beehive logo promo banner for Computing & Info Sciences
CS 320
2025spring
ibarland

Installing Rust
rustup, IDE, debugger

Due: Feb.20 (Thu), at start of class

The purpose of this exercise is to make sure that you have all the Rust tools installed correctly, and that you know how to use them.

Instructions

This assignment has multiple files that you need to submit. Make sure not to miss one; they are described at the bottom of these instructions.

Note that these instructions mention VSCode, However, if you want to try out RustRover, feel free. All the same features should be available one way or another — it's just that you're (more) on your own when it comes to figuring it out.

Your tasks

  1. Install rust (via rustup). and VSCode, along with the necessary Rust extensions for VSCode: Instructions at code.visualstudio.com/docs/languages/rust.
    Note: Alternately, you can install Rust Rover. It seems to require both more disk space and more RAM, compared to VSCode.
    You should verify that you can cargo run a new project from the command-line, per VSCode's Hello World instructions.
  2. We will write a function:
    1. Use cargo from the command-line to create a new Rust Project called hw01. (Cargo will create a file src/main.rs for you.) Add, at the top fo that file, a comment including your name, the course, and the URL of this assignment, radford.edu/~cs320/2025spring-ibarland/Homeworks/install-rust-tools.html.
    2. Write the stub for function called subtract same_sign that accepts two integers and returns a boolean: whether the two inputs have the same sign. For now, your stub should be only enough to let your code compile; the body might be the single word false.
    3. Write a function with unit tests for "subtract"same_sign. Be sure to test inputs 0, 1, many, as well as a negative number, and any interesting combinations of these.

      Hmm, writing unit tests forces us to consider: what is the sign of zero? For this problem, we shall simply declare that 0 can be considered either sign (since +0 = -0 = 0 ?). Being optimists, we will therefore declare that 0 and 3 have the same sign, and that 0 and -3 have the same sign, for the purposes of this function1.

      After this step, you should have code that compiles and runs, but of course cargo test reports that it fails a test, since same_sign is still stubbed out.

    4. Now, complete the body for same_sign.
      hint: While you may certainly use if-else-if statements, you can sneakily just multiply your two inputs, and then (somehow) use that to get your answer; your function body could be as few as 6 characters plus whitespace for readability!
      Do not use num_traits::signum, since we have no idea how to import crates!
    5. Check that your tests pass, with cargo test. If they don't, and you can't fix your function, mention this prominently in a comment near the start of your file.
      Note: No, I won't be able to confirm that you wrote your unit-tests and a stub before completing same-sign's body. However, doing so is good practice that never costs you time, and occasionally saves you a lot of time.
    6. Finally, write main function, which declares and initializes two integer variables. The main function should2 call same-sign, passing it these two variable, and println either “same sign” or “different sign” (and nothing else).
  3. After you run and test your main program, install the debugging tools for Rust. This is by far the hardest step, but if you carefully read the instructions here, then you should be fine. Note that, for Windows, you should scroll to the bottom and install C/C++ build tools first before you install the plugin for VSCode. The build tools can be found a[#:href "https://visualstudio.microsoft.com/visual-cpp-build-tools/"]{here}. If you don't do that, this the VSCode debugger will behave very oddly...

    Then, proceed with these debugging instructions. Once you have both the C / C++ build tools and the appropriate extension installed, you should be able to set breakpoints, run the program in debug mode, stop the program at breakpoints, and step through the program line by line. Make sure to test out this last part: stepping through line by line. If (for Windows) you didn't install C/C++ build tools correctly, then this will behave oddly, making your debugger useless.

Deliverables

Submit the following four files on D2L. Use only the following formats: .rs, .txt, .pdf, .jpg, .png. Notably: Not .docx. Submit each file to D2L separately; do not submit a .zip. You are encouraged to keep screenshots small (i.e. only capturing the part of the screen which shows what's being asked for).

Each of these 4 items is worth 25% of the homework.


1 Hmm, our optimist's approach leaves us with a relation that is not transitive! IRL that'd be a strong hint to re-consider how to classify 0's sign.      
2 Since our main doesn't return anything, we can't have any unit-tests for it. In practice, terminal I/O is often limited to a top-level main, and anything that does actual calculation is in a non-void function which doesn't print, but returns.      

logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.