About This Course

  • We will learn to program in Rust

    • Work through a textbook
    • Write weekly homeworks
    • Everyone: Write a 1000-line project
    • Grads: 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

    curl https://sh.rustup.rs -sSf | sh
    rustup component rustfmt add
    rustup component clippy add
    
  • Now you have access to nightly, beta and stable builds for arbitrary platforms

Hello World In Rust

  • Initialize Cargo project

    cargo init --bin
    
  • Edit provided program

  • 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

  • Simple command-line app

  • Your homework: extend it to do more things.

Last modified: Monday, 1 April 2019, 6:02 PM