Rustプロジェクトの作成
Rustプロジェクトの作成
~
$ cd
~
$ mkdir workspace
~
$ cd workspace
~/workspace
$ cargo new rust_lesson
Creating binary (application) `rust_lesson` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
~/workspace
$ cd rust_lesson
プロジェクトを作成するといくつかのファイル、フォルダが作成される
\RUST_LESSON
│ .gitignore
│ Cargo.lock
│ Cargo.toml
│
├─src
│ main.rs
│
└─target
│ .rustc_info.json
│ CACHEDIR.TAG
│
└─debug
...
srcフォルダ内にmain.rsが格納されていて、これがrustの拡張子。
デフォルトで以下のようにHello World!をプリントするコードが書かれている。
Rustではこのmain関数から実行が始まるようになっている。
fn main() {
println!("Hello, world!");
}
実行方法
cargo runをすることで、コンパイルとプログラムを同時に実行することができる。
~/workspace/rust_lesson (master)
$ cargo run
Compiling rust_lesson v0.1.0 (C:\workspace\rust_lesson)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.77s
Running `target\debug\rust_lesson.exe`
Hello, world!
この記事が気に入ったらサポートをしてみませんか?