GithubHelp home page GithubHelp logo

caorufu / rust-by-practice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sunface/rust-by-practice

0.0 0.0 0.0 2.37 MB

Learning Rust By Practice, narrowing the gap between beginner and skilled-dev with challenging examples, exercises and projects.

Home Page: https://practice.rs

License: Creative Commons Attribution 4.0 International

Shell 0.26% JavaScript 6.70% Rust 75.35% CSS 2.09% Handlebars 15.60%

rust-by-practice's Introduction

English | δΈ­ζ–‡

Practice Rust with challenging examples, exercises and projects

Stars Count studyrut LICENSE

This book was designed for easily diving into and get skilled with Rust, and it's very easy to use: All you need to do is to make each exercise compile without ERRORS and Panics !

Reading online

Features

Part of our examples and exercises are borrowed from Rust By Example, thanks for your great works!

Although they are so awesome, we have our own secret weapons :)

  • There are three parts in each chapter: examples, exercises and practices

  • Besides examples, we have a lot of exercises, you can Read, Edit and Run them ONLINE

  • Covering nearly all aspects of Rust, such as async/await, threads, sync primitives, optimizing, standard libraries, tool chain, data structures and algorithms etc.

  • Every exercise has its own solutions

  • The overall difficulties are a bit higher and from easy to super hard: easy 🌟 medium 🌟🌟 hard 🌟🌟🌟 super hard 🌟🌟🌟🌟

What we want to do is fill in the gap between learning and getting started with real projects.

πŸ… Contributors

Thanks to all of our contributors!


πŸ† Special thanks to our English editor:


Tanish-Eagle

Running locally

We use mdbook building our exercises. You can run locally with below steps:

  • Clone the repo
$ git clone [email protected]:sunface/rust-by-practice.git
  • Install mdbook using Cargo
$ cargo install mdbook
  • For Book in English
$ cd rust-by-practice && mdbook serve en/
  • For Book in Chinese
$ cd rust-by-practice && mdbook serve zh-CN/

Some of our exercises

🌟🌟🌟 Tuple struct looks similar to tuples, it has added meaning the struct name provides but has no named fields. It's useful when you want give the whole tuple a name, but don't care the fields's names.

// fix the error and fill the blanks
struct Color(i32, i32, i32);
struct Point(i32, i32, i32);
fn main() {
    let v = Point(___, ___, ___);
    check_color(v);
}

fn check_color(p: Color) {
    let (x, _, _) = p;
    assert_eq!(x, 0);
    assert_eq!(p.1, 127);
    assert_eq!(___, 255);
 }

🌟🌟 Within the destructuring of a single variable, both by-move and by-reference pattern bindings can be used at the same time. Doing this will result in a partial move of the variable, which means that parts of the variable will be moved while other parts stay. In such a case, the parent variable cannot be used afterwards as a whole, however the parts that are only referenced (and not moved) can still be used.

// fix errors to make it work
#[derive(Debug)]
struct File {
    name: String,
    data: String,
}
fn main() {
    let f = File {
        name: String::from("readme.md"),
        data: "Rust By Practice".to_string()
    };

    let _name = f.name;

    // ONLY modify this line
    println!("{}, {}, {:?}",f.name, f.data, f);
}

🌟🌟 A match guard is an additional if condition specified after the pattern in a match arm that must also match, along with the pattern matching, for that arm to be chosen.

// fill in the blank to make the code work, `split` MUST be used
fn main() {
    let num = Some(4);
    let split = 5;
    match num {
        Some(x) __ => assert!(x < split),
        Some(x) => assert!(x >= split),
        None => (),
    }
}

rust-by-practice's People

Contributors

863056768 avatar codemystery avatar cuishuang avatar djrmarques avatar dongzl avatar fireindark707 avatar furtherun avatar ganesh47 avatar greyhawk avatar gtm-nayan avatar ilovetangy avatar joleeee avatar josephtlyons avatar kaichii avatar katopz avatar likzn avatar linbingquan avatar lubical avatar mikucy avatar rackar avatar situ2001 avatar skarlett avatar sunface avatar sweet2honey avatar tailless-monkey avatar tangdingga1 avatar tanish-eagle avatar tu6ge avatar wgdzlh avatar zongzi531 avatar

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.