About This Course

  • We will learn to program in Rust

    • Work through a textbook
    • Write weekly(ish) homeworks
    • Everyone: Write a 1000-line project
    • Grads: Option to instead write a 5-page research paper
  • Goal: leave as competent Rust programmer (course objectives in syllabus)

About Rust

  • Rust is a "systems programming language" intended as a replacement for C/C++

  • Rust offers a unique type system that allows static automatic memory management: mallocs and frees can be inserted by the program as needed

    • The automatic memory management constraints make writing Rust programs harder than one might expect
  • Rust provides safety guarantees against common types of error. It also provides an "unsafe" mode to escape some of these guarantees when needed

  • Rust programs tend to have similar performance to C programs, similar readability to C++ programs, be harder to write than either, and to be reliable and safe

  • Concurrency and functional programming features are first-class in Rust

  • Nice module and separate compilation system with package manager

Installing Rust

  • Install rustup tool. On Linux

    curl https://sh.rustup.rs -sSf | sh
    
  • Add necessary components

    rustup component rustfmt add
    rustup component clippy add
    
  • Make sure your PATH environment variable is set up

Hello World In Rust

  • Initialize Cargo project

    cargo init --bin
    
  • Edit provided program (not actually needed)

  • Build and run program

    cargo build
    cargo run
    

Rust Testing

  • Built-in (OK) support for unit tests integrated with language and Cargo

  • Can express positive and negative tests, conditional tests

Rust Program Documentation

  • Integrated doc comments as expected

  • Neat feature: doc tests

  • Integrated with Cargo

  • Works better with libraries than binaries

Rust Language Documentation

  • The course textbook

  • Other books (?)

  • "The Rust Book" online (second edition, mostly)

  • The API docs

Book Example: GCD

Last modified: Tuesday, 30 March 2021, 3:12 PM