コマンドで一発!
情報源
手順
1. 作成
$ cargo new 任意プロジェクト名 --bin
以下のようなファイルが作成される。
- 任意プロジェクト名
- Cargo.toml
- src/
- main.rs
Cargo.toml
[package] name = "hello_world" version = "0.1.0" authors = ["ytyaru <メールアドレス>"] edition = "2018" [dependencies]
authorsの情報はGitの設定から持ってきたと思われる。editionが2018
と古いのは謎。
main.rs
fn main() { println!("Hello, world!"); }
2. ビルド&実行
$ cargo run
なお、2回目以降はコードに変更なければビルドしない。よって高速に実行できる。
おまけ
ヘルプ
$ cargo new --help cargo-new Create a new cargo package at <path> USAGE: cargo new [OPTIONS] <path> OPTIONS: --registry <REGISTRY> Registry to use --vcs <VCS> Initialize a new repository for the given version control system (git, hg, pijul, or fossil) or do not initialize any version control at all (none), overriding a global configuration. [possible values: git, hg, pijul, fossil, none] --bin Use a binary (application) template [default] --lib Use a library template --edition <YEAR> Edition to set for the crate generated [possible values: 2015, 2018] --name <NAME> Set the resulting package name, defaults to the directory name -v, --verbose Use verbose output (-vv very verbose/build.rs output) -q, --quiet No output printed to stdout --color <WHEN> Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date -Z <FLAG>... Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details -h, --help Prints help information ARGS: <path>
以下でライブラリ用プロジェクトを作成できるっぽい。
cargo new 任意プロジェクト名 --lib
前回まで
対象環境
- Raspbierry pi 3 Model B+
- Raspbian stretch 9.0 2018-11-13
- bash 4.4.12(1)-release
- rustc 1.34.2 (6c2484dc3 2019-05-13)
- cargo 1.34.0 (6789d8a0a 2019-04-01)
$ uname -a Linux raspberrypi 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU/Linux