diff --git a/Readme.md b/Readme.md index 2881ac7..2c869f1 100644 --- a/Readme.md +++ b/Readme.md @@ -41,7 +41,7 @@ Although they are so awesome, we have our own secret weapons :) - 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 and standard libraries etc. +- 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 diff --git a/src/why-exercise.md b/src/why-exercise.md index f9841be..66dbf81 100644 --- a/src/why-exercise.md +++ b/src/why-exercise.md @@ -1,12 +1,32 @@ -# Rust By Practice +
+ +
+ +

Practice Rust with challenging examples, exercises and projects

+ +
-This book was designed for easily diving into Rust, and it's very easy to use: All you need to do is to make each exercise compile without ERRORS and Panics ! +[![Stars Count](https://img.shields.io/github/stars/sunface/rust-by-practice?style=flat)](https://github.com/sunface/rust-by-practice/stargazers) [![Forks Count](https://img.shields.io/github/forks/sunface/rust-by-practice.svg?style=flat)](https://github.com/naaive/orange/network/members) +[![LICENSE](https://img.shields.io/badge/license-mit-green?style=flat)](https://github.com/sunface/rust-by-practice/blob/master/LICENSE) +
-## Read online +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 - [English](https://practice.rs) - [简体中文](https://zh.practice.rs) + +## Running locally + +We use [mdbook](https://rust-lang.github.io/mdBook/) building our exercises. You can run locally with below steps: +```shell +$ cargo install mdbook +$ cd rust-by-practice && mdbook serve +``` + ## Features Part of our examples and exercises are borrowed from [Rust By Example](https://github.com/rust-lang/rust-by-example), thanks for your great works! @@ -17,69 +37,10 @@ Although they are so awesome, we have our own secret weapons :) - 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 and standard libraries** etc. +- 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.** - -## 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. - -```rust - -// 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. -```rust - -// 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. -```rust,editable - -// 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 => (), - } -} -``` diff --git a/zh-CN/src/why-exercise.md b/zh-CN/src/why-exercise.md index 7f28e79..00a134e 100644 --- a/zh-CN/src/why-exercise.md +++ b/zh-CN/src/why-exercise.md @@ -1,38 +1,49 @@ -# Rust By Practice -通过简单到困难的示例、练习及小型项目来练习和实践 Rust。 +
+ +
+ +

通过有挑战性的示例、练习题、实践项目来提升 Rust 水平,建立从入门学习到上手实战的直通桥梁

+ +
+ +[![Stars Count](https://img.shields.io/github/stars/sunface/rust-by-practice?style=flat)](https://github.com/sunface/rust-by-practice/stargazers) [![Forks Count](https://img.shields.io/github/forks/sunface/rust-by-practice.svg?style=flat)](https://github.com/naaive/orange/network/members) +[![LICENSE](https://img.shields.io/badge/license-mit-green?style=flat)](https://github.com/sunface/rust-by-practice/blob/master/LICENSE) +
+ +本书的目标是通过大量的实战练习帮助大家更好的学习和上手使用 Rust 语言。书中的练习题非常易于使用:你所需的就是在线完成练习,并让它通过编译。 + ## 在线阅读 -- [英文地址](https://practice.rs) -- [中文地址](https://zh.practice.rs) - -## 为何又一个练习? +- [https://zh.practice.rs](https://zh.practice.rs) -[Rustlings](https://github.com/rust-lang/rustlings) 和 [Rust By Example](https://github.com/rust-lang/rust-by-example) 都是非常好的练习方式,但是我们还提供了一些独家秘笈: +## 本地运行 -1. 更多的练习题,难度从简单到困难 +我们使用 [mdbook](https://rust-lang.github.io/mdBook/) 构建在线练习题,你也可以下载到本地运行: +```shell +$ cargo install mdbook +$ cd rust-by-practice && mdbook serve +``` -2. 覆盖面更广,除了 Rust 语言本身外,还包括了**async异步编程, 多线程, 并发原语, 性能优化和标准库等内容s** - -3. 通过一些小型实践项目来实践 Rust - -4. 支持英语和中文 +## 特性 -## 如何使用 +部分示例和习题借鉴了 [Rust By Example](https://github.com/rust-lang/rust-by-example), 书中的示例真的非常棒! -- 大家可以在线编辑和运行所有练习 - -- **唯一的目标就是让每一道题都编译通过,没有错误也没有 panic !** - -- 难度等级: 简单: 🌟 中等: 🌟🌟 困难: 🌟🌟🌟 地狱: 🌟🌟🌟🌟 +尽管它们非常优秀,我们这本书也有自己的秘密武器 :) +- 每个章节分为三个可选部分:示例、练习和实践项目 -## 社区贡献 +- 除了示例外,我们还有大量的高质量练习题,你可以在线阅读、修改和编译它们 -我们欢迎所有类型的社区贡献,包括新的练习题、bug和文字修正等。 +- 覆盖了 Rust 语言的几乎所有方面:基础语言特性、高级语言特性、async/await 异步编程、多线程、并发原语、性能优化、工具链使用、标准库、数据结构和算法等 +- 每一道练习题都提供了解答 -## Buy me a ... 🌟? +- 整体难度相对更高,更加贴近于实战难度: 简单 🌟 , 中等 🌟🌟 , 困难 🌟🌟🌟 , 地狱 🌟🌟🌟🌟 + +**总之,我们想做的就是解决入门学习后,不知道该如何运用的问题,毕竟对于 Rust 来说,从学习到实战,中间还隔着数个 Go语言 的难度** + +## 喜欢我们精心设计的练习题吗? 对我们来说,来自读者大大的肯定比什么都重要,因此一个 [Github star](https://github.com/sunface/rust-by-practice) 要比一杯咖啡更让我们开心,而且现在它在跳楼打折,无需 998 , 仅需 0 元钱 :)