◾️はじめに
https://dk521123.hatenablog.com/entry/2023/04/22/234808
の続き。 Rust の 勉強を再開したので、 ひとまず、Hello worldでもやってみる
目次
【1】プロジェクト作成 1)補足:cargo 【2】プログラム修正 1)補足:「!」について 【3】実行 方法1:VS Codeでの実行 方法2:cargoコマンドでの実行 【4】Appendix-A:Rustの命名規則
【1】プロジェクト作成
* 「cargo new <プロジェクト名>」でプロジェクト作成
コマンド例
# cargo new <プロジェクト名>
cargo new first_rust_project
実行後のフォルダ構成
├─.vscode
│ └─ launch.json
└─first_rust_project ... プロジェクト
├─src
│ └─ main.rs ... メイン関数
├─Cargo.toml
└─target
1)補足:cargo
* cargo:Rustのビルドシステム兼パッケージマネージャ * Cargo.toml:Cargoの設定ファイル(TOML形式) cf. cargo = 貨物, 積み荷
【2】プログラム修正
* VS Code で ./first_rust_project/src/main.rs を修正してみる
修正例
fn main() { println!("Hello, world!!!?"); }
1)補足:「!」について
* 「マクロ」であることを示すもの
マクロ
* コンパイル時にトークンツリーを処理して、最終的なコードに展開 => コードを生成するコード
https://doc.rust-jp.rs/book-ja/ch19-06-macros.html
【3】実行
方法1:VS Codeでの実行
* VS Code の ./first_rust_project/src/main.rs 内に表示されている 「run」をクリックし、実行 => 実行時にエラーが表示される場合、「【3】トラブルシュート」を参照
実行例
* Executing task: C:\Users\user\.cargo\bin\cargo.exe run --package first_rust_project --bin first_rust_project
Compiling first_rust_project v0.1.0 (C:\xxx\xxxx\first_rust_project)
Finished dev [unoptimized + debuginfo] target(s) in 0.74s
Running `target\debug\first_rust_project.exe`
Hello, world!!!?
* Terminal will be reused by tasks, press any key to close it.
方法2:cargoコマンドでの実行
# Step0: プロジェクトへの移動 cd first_rust_project # Step1: ビルド cargo build Compiling first_rust_project v0.1.0 (/...) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.39s # Step2: 実行 cargo run Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s Running `target/debug/first_rust_project` Hello, world!!!?
【4】Appendix-A:Rustの命名規則
* Rust では、以下を採用 (Pythonに近いイメージ?) + スネークケース (snake_case) + アッパーキャメルケース (UpperCamelCase) * 命名規則は RFC 430 にまとめられている
https://github.com/rust-lang/rfcs/blob/master/text/0430-finalizing-naming-conventions.md
関連記事
Rust ~ 環境構築編 ~
https://dk521123.hatenablog.com/entry/2023/04/22/234808
Rust ~ cargoコマンド ~
https://dk521123.hatenablog.com/entry/2025/12/12/011304
Rust ~ コメント ~
https://dk521123.hatenablog.com/entry/2025/12/13/000224
Rust ~ 制御文 ~
https://dk521123.hatenablog.com/entry/2025/12/07/234508
Rust ~ 変数 / データ型 ~
https://dk521123.hatenablog.com/entry/2025/12/05/000647
Rust ~ 複合型 / コレクション ~
https://dk521123.hatenablog.com/entry/2025/12/06/004709
Rust ~ enum / 列挙型 ~
https://dk521123.hatenablog.com/entry/2025/12/03/000831
Rust ~ 保有権 ~
https://dk521123.hatenablog.com/entry/2023/05/04/213726
Rust ~ 関数 / クロージャ ~
https://dk521123.hatenablog.com/entry/2025/12/09/094909
Rust ~ mod ~
https://dk521123.hatenablog.com/entry/2025/11/29/221911
Rust ~ crate / module ~
https://dk521123.hatenablog.com/entry/2025/12/11/234320
Rust ~ struct/impl/trait ~
https://dk521123.hatenablog.com/entry/2025/11/30/222255
Rust ~ Option型 ~
https://dk521123.hatenablog.com/entry/2025/12/01/223443
Rust ~ Error handling(Result型 / ?演算子) ~
https://dk521123.hatenablog.com/entry/2025/12/02/000346
Rust ~ Axum / 入門編 ~
https://dk521123.hatenablog.com/entry/2023/09/02/224707
Rust ~ Axum / Docker ~
https://dk521123.hatenablog.com/entry/2025/12/08/220615
Rust ~ Axum / REST ~
https://dk521123.hatenablog.com/entry/2025/11/27/145159
Rust template engine ~ Askama / 入門編 ~
https://dk521123.hatenablog.com/entry/2025/12/04/000102
Visual Studio Code ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2019/10/20/230323
sqlparser-rs ~ SQL Parser for Rust ~
https://dk521123.hatenablog.com/entry/2023/06/12/000000