Course Syllabus

Performant Software Systems with Rust

Instructor · Overview · Topics · Assignments · Course Project · Grading · Accommodations

Instructor

Baochun Li, Professor (bli@ece.toronto.edu)

Overview

This course aims to develop a practical and in-depth understanding on best practices of building modern software systems that are memory safe, highly performant, and secure, using the Rust programming language.

This course covers most of the basics on reading and writing Rust code, including important features in Rust, such as ownership and borrowing, lifetimes, traits, generics, error handling, functional programming, and smart pointers. After covering the basics, the course focuses on two advanced topics: (1) it covers asynchronous programming in Rust, and shows how it can be used to develop performant servers with asynchronous concurrency. (2) it introduces idiomatic Rust and design patterns that can be useful when building large software systems.

Due to recent advances of generative AI technologies on coding, the emphasis in this course will be on reading and understanding Rust programs, but some exposure to writing Rust code will be a part of the course as well, in the form of four programming assignments in a dedicated Rust playground developed for this course.

Lecture Topics

The following is a tentative list of topics that will be covered in this course:

Introduction to the Course

  • About me
  • Goals and the course structure (4 assignments, 1 project)
  • Course website
  • Textbook
  • Grading policy
  • Advantages of the Rust programming language

Learning Rust the Hands-On Way

  • Reading the errors carefully
  • Installing and using the Rust toolchain
  • Creating, building, and running the first Rust project
  • Implementing a guessing game

Basic Programming Concepts

  • Mutable and immutable variabls
  • Static types
  • Scalar data types
  • Compound data types
  • Functions
  • If expressions
  • Loops

Ownership and the String Type

  • Ownership: a unique feature in Rust towards memory safety
  • The String type
  • References and borrowing
  • String slices

Structs and Enums

  • Defining and instantiating structs
  • Methods
  • Enums
  • Options
  • Pattern matching
  • The power of enums
  • Characteristics of object-oriented languages

Error Handling

  • Recoverable and unrecoverable errors
  • Handling unrecoverable errors with panic!
  • Handling recoverable errors with Result
  • To panic! or not to panic!

Vectors and Hash Maps

  • Storing lists of values in vectors
  • Storing key-value pairs in hash maps

Generics and Traits

  • Generic data types
  • Traits: defining shared behaviour across structs

Lifetimes

  • Basic concepts of lifetimes
  • Providing hints to the compiler using lifetimes

Functional Rust

  • Closures: anonymous functions
  • Processing a collection of items with iterators

Smart Pointers

  • Using Box<T> to allocate memory on the heap
  • Trait objects
  • Dynamically sized types and the Sized trait
  • Wide pointers
  • The Deref trait and deref coercion
  • The Drop trait
  • Rc<T>, the reference-counted smart pointer
  • RefCell<T> and the interior mutability pattern

Fearless Concurrency — Threads

  • Multi-threaded programming
  • The actor model
  • Message passing using channels
  • Send + Sync marker Traits
  • Atomic types from the Rust standard library

Asynchronous Rust

  • Asynchronous Rust with stackless coroutines
  • Asynchronous runtimes
  • Futures and async/.await
  • A real-world example: page_title()
  • Desugaring async and `#[tokio::main]
  • Deep dive: What’s a Future anyway?
  • Pin and the Unpin marker trait
  • What’s a Waker?
  • Spawning and joining tasks

Best Practices and Idiomatic Rust

  • Using Clippy for static checking
  • Writing and running tests using cargo test
  • Unit vs. integration tests
  • Managing large projects with packages, crates, and modules
  • Idiomatic Rust and design patterns

Assignments

Four sets of hands-on programming assignments are given for take-home completion in this course. Each assignment should be completed on an individual basis, using Rust as the programming language. No generative AI technologies are allowed when completing these assignments; they are designed as manual coding exercises. Refer to the AI policy below for more details.

Reversi Board Game

In this assignment, you are expected to build a command-line utility to allow two human players to play the Reversi board game to completion. Its implementation uses basic types and control flows, and interacts with the user.

Search Utility

In this assignment, you are asked to build a simple command-line search utility that implements the basic functionality of the UNIX grep command.

Web Client

In this assignment, you are expected to implement a command-line utility that makes HTTP requests, similar in spirit to the curl UNIX utility. This assignment will help students gain more experiences on using external crates in the Rust ecosystem as dependencies, and on handling errors.

Web Server

In this final assignment in the course, you are expected to implement a simple web server to maintain a personal music library. This assignment will help students gain experience developing a more complex program that utilizes multiple CPU cores concurrently, implements persistent data storage, and incorporates external crates from the Rust ecosystem as dependencies.

In-class quizzes

Six in-class quizzes will be held in the following lectures: September 23, September 30, October 14, November 11, November 25, and December 2. Each in-class quiz will consist of five multiple-choice questions, and will be conducted in 5 minutes of time, one minute on average for each question. In class quizzes cannot be participated online, as they are conducted on paper. All in-class quizzes will be conducted at the end of the two-hour lecture (starting 4:55 p.m. and ending 5:00 p.m.), in case you may miss a part of the lecture.

Your scores (with a maximum score of 5) in these in-class quizzes will account for 10% of the term grade. Out of the six in-class quizzes, the highest four scores will be used for the term grade, each account for 2.5%. For example, if your score is 4 out of 5 in an in-class quiz, it will contribute 2% to the term grade if it is among your best four.

All in-class quizzes will be multiple choice questions, and there will only be one correct answer for each question. To answer these questions, it is recommended that you bring a few pencils and an optional eraser (pens are allowed as well, but not the best).

Examinations

This course will have a midterm and a final examination, to be conducted on paper. Both examinations will have a duration of 110 minutes (3:10 p.m. — 5 p.m.), and will consist of multiple choice questions only. These examinations do not require you to write Rust code — writing code as a skill is practiced during the take-home programming assignments; instead, they focus on reading and understanding Rust code, since many multiple choice questions will require reading Rust code before answering them.

AI Policy

Programming — including both reading and writing code — will soon become a lost art, and one of the objectives in this course is for you to acquire such a skill for the Rust programming language, one of the hardest programming languages to learn. For this reason, this course does not use generative AI technologies. None of the lecture slides were written by generative AI, and this website is hand-written.

No AI is allowed when writing the programming assignments. The in-class quizzes, midterm examination, and final examination are all closed-book closed-notes, no calculators, no cell phones, and no computers are allowed. All you need to bring will be an ample supply of pencils and an optional eraser. Pens are allowed too if that is your preference. All quizzes, midterm examination, and the final examination will be conducted on paper, to be handed out before the quizzes or examinations to the class.

It is mandatory that the take-home programming assignments should be written in a dedicated new Rust programming playground, called Rustrace, designed and implemented by the instructor for conducting manual coding exercises. Each programming assignment requires at least 8-10 hours of your time; it is strongly recommended that you start early, and allow at least several days before the deadline.

Grading

  • Assignments 40%
    • 10% each
  • In-class quizzes 10% (the top 4 out of 6 quizzes)
  • Midterm examination 20%
  • Final examination 30%

Accommodations

The University of Toronto supports accommodations for students with diverse learning needs, which may be associated with mental health conditions, learning disabilities, autism spectrum, ADHD, mobility impairments, functional/fine motor impairments, concussion or head injury, visual impairments, chronic health conditions, addictions, D/deaf, deafened or hard of hearing, communication disorders and/or temporary disabilities, such as fractures and severe sprains, or recovery from an operation. If you have a learning need requiring an accommodation the University of Toronto recommends that students register with Accessibility Services as soon as possible. We know that many students may be hesitant to reach out to Accessibility Services for accommodations. The purpose of academic accommodations is to support students in accessing their academics by helping to remove unfair disadvantages. We can assess your situation, develop an accommodation plan with you, and support you in requesting accommodation for your course work. The process of accommodation is private; we will not share details of your needs or condition with any instructor.

If you feel hesitant to register with us, we encourage you to reach out for further information and resources on how we can support. It may feel difficult to ask for help, but it can make all the difference during your time here.

Phone: 416-978-8060

Email: accessibility.services@utoronto.ca

Equity, Diversity and Inclusion

U of T Engineering strives to create equitable and inclusive learning environments for all individuals. Each person has their own lived experiences and socio-cultural identities that shape their worldview and their experiences with privilege and oppression.

Looking for community? Feeling isolated? Not being understood or heard?

You are not alone. You can talk to anyone in the Faculty that you feel comfortable approaching, anytime — professors, instructors, teaching assistants, department academic advisors, student leaders or the Assistant Dean of Diversity, Inclusion and Professionalism.

You belong here. In this class, the participation and perspectives of everyone is invited and encouraged. The broad range of identities and the intersections of those identities are valued and create an inclusive team environment that will help you achieve academic success. You can read the evidence for this approach here.

You have rights. The University Code of Student Conduct and the Ontario Human Rights Code protect you against all forms of harassment or discrimination, including but not limited to acts of racism, sexism, Islamophobia, antisemitism, homophobia, transphobia, ableism, classism and ageism. Engineering denounces unprofessionalism or intolerance in language, actions or interactions, in person or online, on- or off-campus. Engineering takes these concerns extremely seriously and you can confidentially disclose directly to the Assistant Dean for help here.

Support for Indigenous Students

If you are an Indigenous engineering student, you are invited to join a private Discord channel to meet other Indigenous students, professors, and staff, chat about scholarships, awards, work opportunities, Indigenous-related events, and receive mentorship. Email Professor Bazylak or Darlee Gerrard if you are interested.

Indigenous students at U of T are also invited to visit Nations House’s (FNH) Indigenous Student Services for culturally relevant programs and services. If you want more information on how to apply for Indigenous specific funding opportunities, cultural programs, traditional medicines, academic support, monthly social events or receive the weekly newsletter, go to the FNH website, email or follow FNH on social media: Facebook, Instagram, or TikTok. A full event calendar is on the CLNX platform. Check CLNX often to see what new events are added!

As part of the Faculty’s commitment to improving Indigenous inclusion, all U of T Engineering faculty, staff and students are called upon to start or continue their personal journeys towards understanding and acknowledging Indigenous peoples’ history, truths and culture. The Faculty’s 2018 Blueprint for Action report identified many actions to (re)building relationships between U of T Engineering and Indigenous peoples. These actions also align with the Truth and Reconciliation Commission of Canada’s Calls to Action.

One action is for non-Indigenous people to make a Land Acknowledgement in lectures and/or before important meetings. For reference, here are examples from the University and the COU: University of Toronto’s Statement of Acknowledgement of Traditional Land and Council of Ontario Universities’ Acknowledgement of Traditional Land.

To combat the fear that land acknowledgements have become largely performative and rote, we advise that the acknowledgement is done with sincerity and reflection on how you benefit from using the land, and on your commitments to Truth and Reconciliation. Take this training to learn more.

As an environmentalist, I have always been appreciative of the fact that right now we are in the territory covered by the Dish With One Spoon Wampum Belt. This is a treaty originally by the Anishinaabe, Mississaugas, and the Haudenosaunee. It is not a rights-based agreement, but rather a responsibility-based agreement. Hundreds of years ago the First Nations People in this area recognized our responsibility to share and protect the land. Since that first wampum belt many other First Nations and Europeans have joined in this treaty. The First Nations close ties to the land enabled them to see the needs of the land when others could not or choose not to see. For that I am thankful to the Indigenous People of this land we work and study on.

Looking for help personalizing the land acknowledgement? Professor Jason Bazylak is the Dean’s Advisor on Indigenous Inclusivity. He is willing to chat with anyone on how to go about presenting and/or discussing this with your class. He can be reached at jason.bazylak@utoronto.ca (after January 2024). In 2023, you can contact Darlee Gerrard in the Outreach Office at darlee.gerrard@utoronto.ca or Marisa Sterling, P.Eng. in the Dean’s Office at marisa.sterling@utoronto.ca.

Wellness and Mental Health Support

As a University of Toronto Engineering student, you have a Departmental Undergraduate Advisor or a Departmental Graduate Administrator who can support you by advising on personal matters that impact your academics. Other resources that you may find helpful are listed on the U of T Engineering Mental Health & Wellness webpage, and a small selection are also included here:

U of T Engineering’s Mental Health Programs Officer

Accessibility Services

Graduate Engineering Council of Students’ Mental Wellness Commission Visit the SGS Grad Hub and click on Resources & Supports. Navigate to Health & Wellness: Graduate Wellness Services at SGS

Academic Success

We encourage you to access these resources as soon as you feel you need support; no issue is too small. If you find yourself feeling distressed and in need of more immediate support, consider reaching out to the counsellors at U of T Telus Health Student Support or visiting U of T Engineering’s Urgent Support — Talk to Someone Right Now.