rust by practice
1.0.0

英语|中文
通过具有挑战性的例子,练习和项目练习生锈
这本书旨在轻松潜入并熟练使用Rust,这很容易使用。您需要做的就是将每个练习编译而不会出错和恐慌!
我们的一部分例子和练习都是从Rust借用的,感谢您的出色作品!
尽管它们太棒了,但我们有自己的秘密武器:)
每一章中有三个部分:示例,练习和实践
除示例外,我们还有a lot of exercises ,您可以在线阅读,编辑和运行它们
涵盖生锈的几乎所有方面,例如异步/等待,线程,同步基原始人,优化,标准库,工具链,数据结构和算法等。
每个练习都有自己的解决方案
总体上的困难有点更高,并且从易于实现:容易?中等的 ??难的 ???超级硬????
我们要做的是填补学习和开始研究实际项目之间的差距。
感谢我们所有的贡献者!
?特别感谢我们的英语编辑:
蕾丝 |
我们使用MDBook构建练习。您可以在以下步骤中在本地运行:
$ git clone [email protected]:sunface/rust-by-practice.git$ cargo install mdbook$ cd rust-by-practice && mdbook serve en/$ cd rust-by-practice && mdbook serve zh-CN/???元组结构看起来与元组相似,它添加了结构名称提供但没有命名字段。当您想给整个元组一个名字,但不在乎字段的名称时,这很有用。
// 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 ) ;
}?在单个变量的破坏性中,可以同时使用旁移动和副引用模式绑定。这样做将导致变量的部分移动,这意味着在其他零件停留时将移动变量的一部分。在这种情况下,本以后无法整体使用父变量,但是仍然可以使用(不移动)的零件可以使用。
// 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 ) ;
}?比赛后卫是在模式下在匹配臂中指定的额外条件,必须匹配模式匹配,才能选择该臂。
// 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 => ( ) ,
}
}