30个稳定版本 (4个主要版本)
6.2.0 | 2024年8月9日 |
---|---|
6.1.0 | 2024年7月10日 |
5.6.1 | 2023年9月18日 |
5.5.1 | 2023年5月17日 |
2.1.0 | 2019年11月27日 |
51,891 个星标 & 319 个关注者
165KB
3.5K SLoC
rustlings 🦀❤️
问候并欢迎来到 rustlings
。该项目包含小型练习,让您熟悉阅读和编写Rust代码。这包括阅读并响应编译器消息!
...正在寻找Rustlings的旧版基于Web的版本?请尝试这里
或者,对于初学者,还有其他一些资源
- 《The Book》 - 学习Rust最全面的资源,但有时有点理论化。您将使用此资源与Rustlings一起使用!
- Rust By Example - 通过解决小型练习来学习Rust!它几乎就像
rustlings
,但在线上
入门
注意:如果您使用的是MacOS,请确保已通过以下命令安装Xcode及其开发工具: xcode-select --install
。 注意:如果您使用的是Linux,请确保已安装gcc。Deb: sudo apt install gcc
. Yum: sudo yum -y install gcc
.
您需要安装Rust。您可以通过访问https://rustup.rs来获取它。这也会安装Cargo,Rust的包/项目管理器。
MacOS/Linux
只需运行
curl -L https://raw.githubusercontent.com/rust-lang/rustlings/main/install.sh | bash
或者,如果您想将其安装到不同的路径
curl -L https://raw.githubusercontent.com/rust-lang/rustlings/main/install.sh | bash -s mypath/
这将安装Rustlings并为您提供访问rustlings
命令的权限。运行它以开始吧!
Nix
基本上:克隆最新标签的仓库,最后运行nix develop
或nix-shell
。
# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.6.1)
git clone -b 5.6.1 --depth 1 https://github.com/rust-lang/rustlings
cd rustlings
# if nix version > 2.3
nix develop
# if nix version <= 2.3
nix-shell
Windows
在PowerShell(以管理员身份运行)中,将ExecutionPolicy
设置为RemoteSigned
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
然后,您可以运行
Start-BitsTransfer -Source https://raw.githubusercontent.com/rust-lang/rustlings/main/install.ps1 -Destination $env:TMP/install_rustlings.ps1; Unblock-File $env:TMP/install_rustlings.ps1; Invoke-Expression $env:TMP/install_rustlings.ps1
来安装Rustlings。与MacOS/Linux相同,在安装完成后,您将可以访问rustlings
命令。请注意,这最好在PowerShell中运行,其他终端可能会出现错误。
如果您收到拒绝访问的消息,您可能需要在您的防病毒软件中排除克隆Rustlings的目录。
浏览器
手动
基本上:克隆最新标签的仓库,运行cargo install --path .
。
# find out the latest version at https://github.com/rust-lang/rustlings/releases/latest (on edit 5.6.1)
git clone -b 5.6.1 --depth 1 https://github.com/rust-lang/rustlings
cd rustlings
cargo install --force --path .
如果存在安装错误,请确保您的工具链是最新的。对于最新版本,请运行
rustup update
然后,与上面相同,运行rustlings
以开始。
做练习
练习按主题排序,可以在子目录rustlings/exercises/<主题>
中找到。对于每个主题,都有一个额外的README文件,其中包含一些资源,以帮助您开始该主题。我们强烈建议您在开始之前查看它们。
任务很简单。大多数练习都包含一个错误,导致它们无法编译,而修复这个错误就是您的任务!一些练习也作为测试运行,但rustlings对它们都是一样的处理。要按推荐顺序运行练习,请执行
rustlings watch
这将尝试以预定顺序验证每个练习的完成情况(我们认为这对新入门者来说是最好的)。它还会在您更改exercises/
目录中的文件时自动重新运行。如果您只想运行一次,可以使用
rustlings verify
这将与watch相同,但运行后会退出。
如果您想按照自己的顺序进行,或者只想验证单个练习,可以运行
rustlings run myExercise1
或者使用以下命令运行课程中的下一个未解决的练习
rustlings run next
如果您遇到困难,可以运行以下命令以获取练习的提示
rustlings hint myExercise1
您也可以使用以下命令获取下一个未解决的练习的提示
rustlings hint next
要检查您的进度,可以运行以下命令
rustlings list
自我测试
在每隔几个部分之后,将会有一个测验来测试您对多个部分的知识。这些测验可以在exercises/quizN.rs
中找到。
启用rust-analyzer
运行命令 rustlings lsp
,这将会在项目的根目录生成一个 rust-project.json
文件,这允许 rust-analyzer 解析每个练习。
继续
一旦完成 Rustlings,将新知识运用到实际中!通过构建自己的项目、为 Rustlings 贡献或寻找其他开源项目进行贡献来继续练习你的 Rust 技能。
卸载 Rustlings
如果你想要从系统中移除 Rustlings,有两个步骤。首先,你需要删除安装脚本为你创建的练习文件夹
rm -rf rustlings # or your custom folder name, if you chose and or renamed it
其次,运行 cargo uninstall
来移除 rustlings
二进制文件
cargo uninstall rustlings
现在你应该完成了!
贡献
请参阅 CONTRIBUTING.md。
贡献者 ✨
感谢在 AUTHORS.md 中列出的人 🎉
依赖
~6–19MB
~193K SLoC