Giter Site home page Giter Site logo

ultimate_rust_crash_course's Introduction

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.

ultimate_rust_crash_course's People

Contributors

cleancut avatar disc avatar jamacku avatar jrolfs avatar koddsson avatar lashomb avatar paumava avatar ruxandrafed avatar vkolomeyko avatar zubbbz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ultimate_rust_crash_course's Issues

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 👋

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));   

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.

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.