Rustの始め方
インストール
Section titled “インストール”Rustの主なツールチェーンは
- rustc
- cargo
- rustup
などがある。Arch Linuxのパッケージでは rustup を入れれば cargo も付いてくるのでそれを入れておく。
pacman -S rustupどのバージョンをデフォルトとして使うのかを決める。これを実行しないとエラーになる。
$ cargo -Verror: rustup could not choose a version of cargo to run, because one wasn't specified explicitly, and no default is configured.
$ rustup default stable$ cargo -Vcargo 1.90.0 (840b83a10 2025-07-30)プロジェクトの作成
Section titled “プロジェクトの作成”プロジェクトを作るときは cargo new する。
cargo new package-nameまたは既存のディレクトリを使うなら cargo init でもいい。
cargo initビルドは cargo build を使う。実行ファイルの場合は target/debug ディレクトリ以下にパッケージ名と同じ名前のコマンドが出力される。
cargo buildGoでいうこれはそれ
Section titled “Goでいうこれはそれ”| Go | Rust |
|---|---|
| go fmt | cargo fmt |
| go vet | cargo clippy |
| gofix | cargo fix |
| go install | cargo install |