導入方法は上記のとおりです
わたしはWindows環境で、Rust環境はインストール済みであったため、
https://github.com/rust-lang/rustlings/?tab=readme-ov-file#windows
をコピペして、無事インストールできました
始める
rustlings watch
インストールが終わると、rustlings watch
コマンドで、エクササイズを確認できます
すると、1回目は以下のような出力が出てきます
最近のプログラミング関係は、Astroとかもそうですが、CUIで遊び心がいっぱいですね
Progress: [------------------------------------------------------------] 0/96 (0.0 %) ✓ Successfully ran exercises/intro/intro1.rs!
🎉 🎉 The code is compiling! 🎉 🎉
Output:
====================
Hello and
welcome to...
_ _ _
_ __ _ _ ___| |_| (_)_ __ __ _ ___
| '__| | | / __| __| | | '_ \ / _` / __|
| | | |_| \__ \ |_| | | | | | (_| \__ \
|_| \__,_|___/\__|_|_|_| |_|\__, |___/
|___/
This exercise compiles successfully. The remaining exercises contain a compiler
or logic error. The central concept behind Rustlings is to fix these errors and
solve the exercises. Good luck!
The source for this exercise is in `exercises/intro/intro1.rs`. Have a look!
Going forward, the source of the exercises will always be in the success/failure output.
If you want to use rust-analyzer, Rust's LSP implementation, make sure your editor is set
up, and then run `rustlings lsp` before continuing.
====================
You can keep working on this exercise,
or jump into the next one by removing the `I AM NOT DONE` comment:
14 | // hint.
15 |
16 | // I AM NOT DONE
17 |
18 | fn main() {
Welcome to watch mode! You can type 'help' to get an overview of the commands you can use here.
このエクササイズはうまく動くぜ。残りのエクササイズはコンパイルエラーとかロジックエラーがあるから、見つけて直してね!
このエクササイズのソースコードはexercises/intro/intro1.rs
にあるから見てみてね!
みたいなことが書いてあります
後、rustlings watch
で表示している状態で、エクササイズのソースコードを書き換えると、変更が反映されます(出力がリロードされる)
適当にprintln!で表示しているメッセージを変えてみたり、コンパイルエラーを仕込んだりして、挙動を確認してみました
さて、で、exercises/intro/intro2.rs
から実際の作業を開始します
// intro2.rs
//
// Make the code print a greeting to the world.
//
// Execute `rustlings hint intro2` or use the `hint` watch subcommand for a
// hint.
// I AM NOT DONE
fn main() {
println!("Hello {}!");
}
これを以下のように変更して、
- println!("Hello {}!");
+ println!("Hello {}!", "World!");
以下の通り、出力結果を得られました
エクササイズはこれの繰り返しのようです
Output:
====================
Hello World!!
====================
エクササイズが終わったら、コメント文の// I AM NOT DONE
を削除します
すると、watch
出力が次のエクササイズへと移行します
まとめ
RustlingsをOptions付近まで遊んでみました
まだまだRustについての知見がないため、だいぶてこずったところが多かったです
ですが、ライブラリの使い方がわからない、ライブラリのメソッドに何があるかわからないという状態が多く、ここら辺は慣れでなんとかなるかなと思いました
開発環境、勉強環境とも充実しており、とっつきやすい言語だなという印象です
これから心がけることは
- Rustを書くのに慣れるため、Exampleを実際に入力していく練習をする
- ライブラリのリファレンスの調べ方を身につける
以上です