Rust Programming Fundamentals - one course to rule them all, one course to find them...

Overview

Ultimate Rust Crash Course

This is the companion repository for the Ultimate Rust Crash Course published online, presented live at O'Reilly virtual events, or in person. You will get the most out of this training experience by trying to accomplish the exercises in this repository and watching (or attending) the instructor-led training.

In other words, this repository is for you hands-on-learners!

I use macOS, and that is what I developed this course on. Everything ought to work similarly on major Linux distributions and Windows. Please contact me ASAP if you have trouble with anything on this page.

Did you like this course? Check out the next one: Ultimate Rust 2: Intermediate Concepts

Install Rust

Rust is required for this course! The latest stable version is always recommended.

  • Go to rust-lang.org and click on the Get Started button and follow the instructions to install Rust for your operating system.
    • Please DO NOT install rust via some other package manager. It will probably be a version that is really old.

You should get somewhat similar output if you run commands like the ones below (newer versions are okay). If you already have an old version of Rust installed, then run rustup update to install a newer version.

$ rustc --version
rustc 1.54.0 (a178d0322 2021-07-26)
$ cargo --version
cargo 1.54.0 (5ae8d74b3 2021-06-22)
  • Clone or download this repository to your computer.

Prepare Your Development Environment

Please do the following (see the How To Learn Rust page for details on all of these)

  • Choose an IDE (or Editor) and configure it with Rust support and customize it to your liking
    • VS Code users: Please use the rust-analyzer extension. If you have the rust extension installed, please uninstall it!
    • IntelliJ users: Please use the intellij-rust extension.
  • Choose one place to "find answers" and either introduce yourself (if it's a forum, IRC, etc.) or find the answer to one question you have.
  • Try doing something in Rust! If you don't have a better idea, then just do this:
    • cargo new message
    • cd message
    • cargo run
    • Edit src/main.rs and change the message.
    • cargo run again to see your new message.
  • Check out the descriptions of the tools and books.

Training!

Now you are ready for the training! Go watch the Ultimate Rust Crash Course (or attend the live session) and come back here for the exercises.

Resources

Exercises

Please clone this repository! These exercises are designed as Rust projects for you to edit on your own computer, with the exception of Exercise A (which is just a README.md file).

The exercises are separate Rust projects inside the exercises/ subdirectory. For each exercise, you should:

  • Open the correspondingexercise/EXERCISE_NAME directory in your IDE/Editor
    • Seriously, just open the individual exercise directory in your IDE. If you open the entire repository, your IDE will probably complain that it sees multiple Rust projects.
  • Navigate to the same directory with your Terminal application (so you can run cargo run, etc.)
  • Open up the src/main.rs file.
  • Follow the numbered exercise instructions in the code comments.

If you encounter any problems with the exercises, please feel free to use the online course communication tools to contact me, or open an discussion. Either way. 😄

For your convenience, here is a list of all the exercises, with links to view the code on GitHub.

Projects

  • Invaders - A terminal-based Space Invaders arcade game clone.
Comments
  • Add vscode workspace

    Add vscode workspace

    The rust_analyser extension will display the error 'rust-analyzer failed to discover workspace' in vscode because it doesn't like many separate Rust projects in a single opened folder.

    Added a workspace, if the cloner of this repo opens the workspace instead of the folder all projects will be properly parsed and analysed by Rust.

    opened by GerbenRampaart 2
  • Add reasoning in h_closures_threads for crossbeam

    Add reasoning in h_closures_threads for crossbeam

    I am leaning rust and taking your course (on skillshare if you are currious)) and everything have been super clear so far, the only thing I haven't liked is that you say

        // Time for some fun with threads and channels!  Though there is a primitive type of channel
        // in the std::sync::mpsc module, I recommend always using channels from the crossbeam crate,
        // which is what we will use here.
    

    Without giving a reason why you prefer the crate over the std library. Do you have an article (or know of one) which goes into why crossbeam is better than the std library, or maybe the reason is so simple you can summerize it in a sentence or two?

    The video chapters/lessons never mentions channels either, so as I don't know what channel:: is I have a hard time even understanding it and its user cases.

    opened by Jerakin 2
  • Cannot get points while iterrating over Shots vector

    Cannot get points while iterrating over Shots vector

    Hi, just doing the excersise G-COLLECTIONS_ENUMS and I'm stuck on the last point 3, looping through shots. I'm not really sure how to fix this.

    here is my code:

    // Silence some warnings that could distract from the exercise
    #![allow(unused_variables, unused_mut, dead_code)]
    
    // Someone is shooting arrows at a target.  We need to classify the shots.
    //
    // 1a. Create an enum called `Shot` with variants:
    // - `Bullseye`
    // - `Hit`, containing the distance from the center (an f64)
    // - `Miss`
    //
    // You will need to complete 1b as well before you will be able to run this program successfully.
    enum Shot {
        Bullseye,
        Hit(f64),
        Miss,
    }
    
    impl Shot {
        // Here is a method for the `Shot` enum you just defined.
        fn points(self) -> i32 {
            match self {
                Shot::Bullseye => 5,
                Shot::Hit(x) => {
                    if x < 3.0 {
                        2
                    } else {
                        1
                    }
                },
                Shot::Miss => 0
            }
            // 1b. Implement this method to convert a Shot into points
            // - return 5 points if `self` is a `Shot::Bullseye`
            // - return 2 points if `self` is a `Shot::Hit(x)` where x < 3.0
            // - return 1 point if `self` is a `Shot::Hit(x)` where x >= 3.0
            // - return 0 points if `self` is a Miss
        }
    }
    
    fn main() {
        // Simulate shooting a bunch of arrows and gathering their coordinates on the target.
        let arrow_coords: Vec<Coord> = get_arrow_coords(5);
        let mut shots: Vec<Shot> = Vec::new();
    
        // 2. For each coord in arrow_coords:
        //
        //   A. Call `coord.print_description()`
        //   B. Create the correct variant of `Shot` depending on the value of
        //   `coord.distance_from_center()`
        //      - Less than 1.0 -- `Shot::Bullseye`
        //      - Between 1.0 and 5.0 -- `Shot::Hit(value)`
        //      - Greater than 5.0 -- `Shot::Miss`
    
        for coord in arrow_coords.iter() {
            coord.print_description();
    
            if coord.distance_from_center() > 1.0 {
                shots.push(Shot::Bullseye);
            } else if coord.distance_from_center() >= 1.0 && coord.distance_from_center() <= 5.0 {
                shots.push(Shot::Hit(coord.distance_from_center()))
            } else {
                shots.push(Shot::Miss);
            }
        }
    
        let mut total = 0;
        // 3. Finally, loop through each shot in shots and add its points to total
        
        for shot  in shots.iter() {
            total += shot.points();
        }
    
        println!("Final point total is: {}", total);
    }
    

    The error is pointing at line toal += shot.points() saying

    move occurs because *shot has type Shot, which does not implement the Copy trait

    I know what it means, but I don't know how to get it working. Thank you!

    question 
    opened by marekpetak 2
  • exercise e_ownership_references add

    exercise e_ownership_references add

    I just wrote fn add(a: &i32, b: &i32) -> i32 {a+b} which works correctly, is that intended? There seems to be no manual dereferencing needed, has that changed since your created the exercises? Or is the correct answer *a+*b with explicit dereferencing?

      // Challenge: Write a function "add" that takes *references* to two integer arguments,
        // dereferences them and adds them together, and returns the result.
        //
        println!("1 + 2 = {}, even via references", add(&1, &2));   
    
    opened by KonradHoeffner 1
  • exercise-z: Update note for .grayscale()

    exercise-z: Update note for .grayscale()

    I come across this small TYPO in final exercise:

    https://github.com/CleanCut/ultimate_rust_crash_course/blob/ccb6cd213bb8ce4a1ff2026e5113aa39b17d5fb7/exercise/z_final_project/src/main.rs#L158-L159

    Based on official documentation .grayscale() returns a new image (please see rust doc)

    pub fn grayscale(&self) -> DynamicImage { ... }
    

    PS: Great course full of very useful tips and great exercises. Looking forward for your upcoming rust course.

    opened by jamacku 1
  • Unknown variable reference in Exercise A: answers.md

    Unknown variable reference in Exercise A: answers.md

    Hey there, I'm working through the first exercise and reviewing the answers. I see there's a reference to a loaded variable, but I don't see this mentioned in the readme instructions. Perhaps this was meant to be ready? Small nitpick but thought you might like to know! If not, no worries. Have a good one 👋

    opened by sm1215 1
  • Rename packages and fix a couple of comment errors.

    Rename packages and fix a couple of comment errors.

    Hello!

    I have renamed the packages to their snake case name in order to comply with RFC 940.

    Since that standard packages and crates containing hyphens in their name are not supported by the rust compiler but they are supported by Cargo.

    If a student implements a function in the src/lib.rs file of any of these packages, then importing that function will produce a compile error that may cause confusion in the student.

    For example, in exercise E some students may choose to implement the function inspect in src/lib.rs. When trying to import this function in src/main.rs using the following use statement:

    use e-ownership-references::inspect;
    

    Will produce a compiler error:

    error: expected one of `::`, `;`, or `as`, found `-`
     --> src/main.rs:4:6
      |
    4 | use e-ownership-references::inspect;
      |      ^ expected one of `::`, `;`, or `as`
    
    error: aborting due to previous error
    
    error: could not compile `e-ownership-references`
    

    Also quoting the package name will not resolve the issue as specified in RFC 940.

    The only way to solve this error is by replacing all the hyphens with _ which may cause confusion among students.

    I have also corrected a couple of comments in exercise H.

    Great course BTW 😄 !

    opened by PauMAVA 1
  • Ignore unused variables in exercise e.

    Ignore unused variables in exercise e.

    Not sure if you want this change but I get a compiler warning when running cargo run on this project before I start solving it. I noticed that we are disabling warnings for unused mut so figured we should be ignoring variables as well?

    koddsson@Kristjans-MBP e_ownership_references % cargo run
       Compiling e_ownership_references v0.1.0 (/Users/koddsson/src/koddsson/ultimate_rust_crash_course/exercise/e_ownership_references)
    warning: unused variable: `arg`
     --> src/main.rs:7:13
      |
    7 |     let mut arg: String = std::env::args().nth(1).unwrap_or_else(|| {
      |             ^^^ help: if this is intentional, prefix it with an underscore: `_arg`
      |
      = note: `#[warn(unused_variables)]` on by default
    
    warning: `e_ownership_references` (bin "e_ownership_references") generated 1 warning
        Finished dev [unoptimized + debuginfo] target(s) in 0.71s
         Running `target/debug/e_ownership_references`
    Please supply an argument to this program.
    
    opened by koddsson 0
  • 2022 Overhaul

    2022 Overhaul

    I'm updating a bunch of things to correspond to the big video content refresh I'm doing for the course.

    I'll merge this at the same time I update the course online.

    opened by CleanCut 0
Owner
Nathan Stocks
Rust Instructor & Indie Game Dev. Author of Rusty Engine. Game ecosystem contributor. Family, Food, Rust, Python, Game Engines, Open Source, Maple Trees.
Nathan Stocks
In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang.

Learn Rust What is this? In this repository you can find modules with code and comments that explain rust syntax and all about Rust lang. This is usef

Domagoj Ratko 5 Nov 5, 2022
Unify your game sources in one place and aquire more of them, using modules made by the community.

Project Black Pearl Unify your game sources in one place by using modules made by the community. What is Project Black Pearl? Project Black Pearl (or

Project Black Pearl 8 Jan 15, 2023
OOLANG - an esoteric stack-based programming language where all instructions/commands are differnet unicode O characters

OOLANG is an esoteric stack-based programming language where all instructions/commands are differnet unicode O characters

RNM Enterprises 2 Mar 20, 2022
This is the Rust course used by the Android team at Google. It provides you the material to quickly teach Rust to everyone.

Comprehensive Rust ?? This repository has the source code for Comprehensive Rust ?? , a four day Rust course developed by the Android team. The course

Google 5.2k Jan 3, 2023
The best Intermediate Rust course out there!

Ultimate Rust 2: Intermediate Concepts This is the companion repository for the Ultimate Rust 2: Intermediate Concepts (the followup to the popular Ul

Nathan Stocks 155 Jan 4, 2023
Free Rust 🦀 course in English 🇬🇧

Learn Rust ?? Free Rust ?? course in English ???? This course was inspired by Dcode Before starting to learn a programming language, you need to under

Skwal 10 Jul 5, 2022
Rust Crash Course, by BPB Publications

Rust Crash Course Grasp the fundamentals of programming in Rust and put your knowledge to use. This is the repository for Rust Crash Course ,published

BPB Online 9 Nov 26, 2022
Course Material for Ardan Labs - Ultimate Rust: Foundations

Ultimate Rust 1: Foundations Presented by Ardan Labs, Ultima Rust: Foundations gives you a "zero to hero" class to get you started with Rust. You'll l

Herbert 9 Mar 8, 2023
P523 is a classic compiler course taught by R. Kent Dybvig.

P523 is a classic compiler course taught by R. Kent Dybvig. This repo implements the course using Rust, provides a framework to help you master P523.

Sirius Demon 44 Dec 26, 2022
A tool & library to help you with the compiler course.

Compiler Course Helper Support: eliminate left recursion (require grammar with no cycles or ϵ-production) calculate nullable, first sets, follow, sets

水夕 4 May 2, 2022
The Devils' Programming Language (Quantum Programming Language)

devilslang has roots in Scheme and ML-flavored languages: it's the culmination of everything I expect from a programming language, including the desire to keep everything as minimalistic and concise as possible. At its core, devilslang is lambda-calculus with pattern-matching, structural types, fiber-based concurrency, and syntactic extension.

Devils' Language 2 Aug 26, 2022
🦀 A Rust CLI to find the optimal time to meet given a when2meet URL

when3meet ?? The Rust when2meet CLI Install | Usage | Contributing & Issues | Docs Built with ❤️ and ?? by Garrett Ladley Install cargo install when3m

Garrett Ladley 4 Sep 18, 2023
A rust crate can find first `Err` in `Iterator>` and iterating continuously, without allocation.

Api Document first-err Find the first Err in Iterator<Result<T, E>> and allow iterating continuously. This crate is specifically designed to replace t

null 3 Oct 28, 2023
A Quest to Find a Highly Compressed Emoji :shortcode: Lookup Function

Highly Compressed Emoji Shortcode Mapping An experiment to try and find a highly compressed representation of the entire unicode shortcodes-to-emoji m

Daniel Prilik 13 Nov 16, 2021
Type erased vector. All elements have the same type.

Type erased vector. All elements have the same type. Designed to be type-erased as far as possible - most of the operations does not know about concre

null 7 Dec 3, 2022
A simple library to get all pairs from any Dex and sync reserves.

pair_sync A simple library to get all pairs from any supported Dex and sync reserves. Crates.io Documentation in progress Filename: examples/sync-pair

null 116 Dec 30, 2022
Scans a given directory for software of unknown provinence (SOUP) and dumps them in a json-file

Scans a given directory for software of unknown provinence (SOUP) and writes them to a json-file. The json-file contains name, version and a meta property for each SOUP.

Dunklas 4 Jul 5, 2022
Checks Crusader Kings 3 user mod files for common mistakes and warns about them.

ck3-tiger Pounces on bugs. Checks Crusader Kings 3 user mod files for common mistakes and warns about them. For example: missing localizations, or usi

Richard Braakman 8 Jan 5, 2023
The utility is designed to check the availability of peers and automatically update them in the Yggdrasil configuration file, as well as using the admin API - addPeer method.

Yggrasil network peers checker / updater The utility is designed to check the availability of peers and automatically update them in the Yggdrasil con

null 6 Dec 25, 2022