Docsity

Rust Programming for Beginners, Cheat Sheet of Technology

Partial preview of the text

Download Rust Programming for Beginners and more Cheat Sheet Technology in PDF only on Docsity!

Comprehensive Rust

Martin Geisler

Contents

Welcome to Comprehensive Rust

build passing contributors 345 stars 33k

This is a free Rust course developed by the Android team at Google. The course covers the full spectrum of Rust, from basic syntax to advanced topics like generics and error handling. The latest version of the course can be found at https://google.github.io/ comprehensive-rust/. If you are reading somewhere else, please check there for updates. The course is available in other languages. Select your preferred language in the top right corner of the page or check the Translations page for a list of all available translations. The course is also available as a PDF. The goal of the course is to teach you Rust. We assume you don't know anything about Rust and hope to:

  • Give you a comprehensive understanding of the Rust syntax and language.
  • Enable you to modify existing programs and write new programs in Rust.
  • Show you common Rust idioms.

We call the first four course days Rust Fundamentals.

Building on this, you're invited to dive into one or more specialized topics:

  • Android: a half-day course on using Rust for Android platform development (AOSP). This includes interoperability with C, C++, and Java.
  • Chromium: a half-day course on using Rust in Chromium-based browsers. This includes interoperability with C++ and how to include third-party crates in Chromium.
  • Bare-metal: a whole-day class on using Rust for bare-metal (embedded) development. Both microcontrollers and application processors are covered.
  • Concurrency: a whole-day class on concurrency in Rust. We cover both classical con- currency (preemptively scheduling using threads and mutexes) and async/await con- currency (cooperative multitasking using futures).

Non-Goals

Rust is a large language and we won't be able to cover all of it in a few days. Some non-goals of this course are:

  • Learning how to develop macros: please see the Rust Book and Rust by Example instead.

Assumptions

The course assumes that you already know how to program. Rust is a statically-typed language and we will sometimes make comparisons with C and C++ to better explain or contrast the Rust approach.

If you know how to program in a dynamically-typed language such as Python or JavaScript, then you will be able to follow along just fine too.

This is an example of a speaker note. We will use these to add additional information to the slides. This could be key points which the instructor should cover as well as answers to typical questions which come up in class.

and offer a solution, e.g., by showing people where to find the relevant information in the standard library.

That is all, good luck running the course! We hope it will be as much fun for you as it has been for us!

Please provide feedback afterwards so that we can keep improving the course. We would love to hear what worked well for you and what can be made better. Your students are also very welcome to send us feedback!

Instructor Preparation

  • Go through all the material: Before teaching the course, make sure you have gone through all the slides and exercises yourself. This will help you anticipate questions and potential difficulties.
  • Prepare for live coding: The course involves significant live coding. Practice the examples and exercises beforehand to ensure you can type them out smoothly during the class. Have the solutions ready in case you get stuck.
  • Familiarize yourself with mdbook: The course is presented using mdbook. Knowing how to navigate, search, and use its features will make the presentation smoother.
  • Slice size helper: Press Ctrl + Alt + B to toggle a visual guide showing the amount of space available when presenting. Expect any content outside of the red box to be hidden initially. Use this as a guide when editing slides. You can also enable it via this link.

Creating a Good Learning Environment

  • Encourage questions: Reiterate that there are no โ€stupidโ€ questions. A welcoming atmosphere for questions is crucial for learning.
  • Manage time effectively: Keep an eye on the schedule, but be flexible. It's more important that students understand the concepts than sticking rigidly to the timeline.
  • Facilitate group work: During exercises, encourage students to work together. This can help them learn from each other and feel less stuck.

1.1 Course Structure

This page is for the course instructor.

Rust Fundamentals

The first four days make up Rust Fundamentals. The days are fast-paced and we cover a broad range of topics!

Course schedule:

  • Day 1 Morning (2 hours and 10 minutes, including breaks)

Segment Duration

Welcome 5 minutes Hello, World 15 minutes Types and Values 40 minutes

Segment Duration Control Flow Basics 45 minutes

  • Day 1 Afternoon (2 hours and 45 minutes, including breaks)

Segment Duration Tuples and Arrays 35 minutes References 55 minutes User-Defined Types 1 hour

  • Day 2 Morning (2 hours and 50 minutes, including breaks)

Segment Duration

Welcome 3 minutes Pattern Matching 50 minutes Methods and Traits 45 minutes Generics 50 minutes

  • Day 2 Afternoon (2 hours and 50 minutes, including breaks)

Segment Duration Closures 30 minutes Standard Library Types 1 hour Standard Library Traits 1 hour

  • Day 3 Morning (2 hours and 20 minutes, including breaks)

Segment Duration Welcome 3 minutes Memory Management 1 hour Smart Pointers 55 minutes

  • Day 3 Afternoon (2 hours and 30 minutes, including breaks)

Segment Duration Borrowing 1 hour and 15 minutes Lifetimes 1 hour and 5 minutes

  • Day 4 Morning (2 hours and 50 minutes, including breaks)

Segment Duration Welcome 3 minutes