LoginSignup
0
1

More than 5 years have passed since last update.

Rustのファイル分割 2015

Last updated at Posted at 2018-12-18

プロジェクトの作成

cargo new --bin project1

ファイル構造

Untitled.png

ソースファイルの追加

src直下の場合

src配下にanother.rsを作成
Untitled.png

main.rsから呼び出す

main.rs
mod another;
fn main(){}

サブディレクトリの場合

Rustの仕様により、サブディレクトリの場合はmod.rsをサブディレクトリ内に追加する必要がある。

  1. src\subfolder\another.rsを作成 Untitled.png
  2. src\subfolder\mod.rsを作成 Untitled.png

mod.rsにファイル名を記述する

another.rs
use another;

main.rsから呼び出す

main.rs
mod subfolder;
fn main(){}

main.rsから呼び出すときは、フォルダ名を指定する。

0
1
2

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
0
1