zl程序教程

您现在的位置是:首页 >  其他

当前栏目

rust 入门笔记: rustlings(推荐一些学习rust语法的一些非常好的小练习)

2023-03-07 09:08:34 时间

rustlings

推荐一个学习rust非常好的repo:

Small exercises to get you used to reading and writing Rust code! - 学习rust语法的一些非常好的小练习

This project contains small exercises to get you used to reading and writing Rust code. This includes reading and responding to compiler messages!

这里放一下我的解答的地址:

https://github.com/yunwei37/os-summer-of-code-daily

第一天的这些部分都比较简单:

  • quiz 1-4:一般是对应于上一章节刚完成的内容
  • variables:变量
  • if:if表达式
  • function:函数
  • primitive_types:主要类型
  • structs:结构体
  • strings:字符串
  • enums:枚举
  • tests:测试
  • modules:模块
  • macros:宏定义
  • move_semantics:将值赋给另一个变量时移动它

第二天:

  • errors:错误处理,Ok and Err
  • option:匹配 Option
  • clippy:一个rust的静态代码分析工具(之前已经碰到好多遍了
  • standard_library_types:这边讲标准库里面各种类型的使用,可能是最复杂的一部分;包含Arc、Box、迭代器等;
  • traits:定义与使用;
  • generics:泛型
  • threads:线程(这里我是用mutex包装了一下
  • conversions:rust的类型转换

这些练习可以深刻让人感受到如何和编译器编译器作艰苦卓绝的斗争