1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

こんにちは。Rustでバックエンド開発をしている奏です。
本記事では、Rustをこれから始める人むけにRustのインストール方法や初期セットアップ、rustupやcargoとは?みたいなことをやります。

Hello rustup!

まず、rustupとは何か、rustupというのはRustという言語のバージョン管理やCargoのセットアップ、メンテナンスを行うものです。
Rustを書くにはまず、rustupをインストールしないと話にならないのでインストールしてください。
こちらからrustupをインストールしてください。
rustupをインストールすると、自動的にオフラインドキュメントや、cargoなども同時にセットアップされます。

Hello Cargo!

さて、Cargoとは何か、CargoというのはRustのコードのビルドやコンパイル、依存関係の管理をはじめとし、rustupを簡略化、またはrustupではできないことをやってくれます。
cargoのコマンドに関しては後日cargoのコマンド一覧などで公開します。

Hello World!

いよいよコードを書いていきます。
まずは、 Rustプロジェクトを作成しましょう。
VSCodeなどコードエディタでフォルダに移動し、コマンドcargo new {プロジェクト名}を実行しましょう。
実行すると、指定したプロジェクト名のフォルダが生成されます。
生成されたフォルダには以下のファイルが含まれています。

  • cargo.toml
  • .git
  • .gitignore
  • src/main.rs

Cargo.tomlはRustプロジェクトのパッケージを管理します(バージョンやプロジェクト名、ビルド方法や依存関係など)
.git.gitignoreは Rustとはちょっと違うものなので言及しません。

src/main.rsには次のコードが書かれています。

fn main(){
    println!("Hello World!");
}

Rustプロジェクトのルート(cargo.tomlがあるディレクトリ)でcargo runを実行するとコンソールにHello World!と出力されます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?