- Rust メモ
test::black_box
→ cargo bench 実行時の最適化を回避
「nightly toolchain not installed. Install?」と言われたので入れた。その後 nightly を削除したら「RLS could not be started.」と言われた。
ユーザー設定に "rust-client.channel": "stable"
を入れて Visual Studio Code を再起動たら解消した。
rustup component list
- システムにセットアップされている Rust システムのリスト
rustup toolchain list
- デフォルトでどの Rust システムを使用するか
rustup default stable
rustup default nightly
rustup toolchain remove nightly
rustup toolchain install stable
rustup component add rust-src
rustup installer をみつけてきて実行します。
シンタックスハイライトとかに使うもの?? (Rust language support は Racer ではないぽい)
cargo install racer
rustup component add rust-src
curl https://sh.rustup.rs -sSf | sh
下記の質問には無言で enter
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
Rust is installed now. Great!
といわれたら ~/.cargo/bin
を PATH に追加するように言われるので追加。
追加したらログアウト & ログイン
rustc --version
rustc hello.rs
で Go よりもちょっと大きなバイナリ hello* ができる。
cargo new testapp2 --bin
cd testapp2
cargo build
cargo run
または
mkdir testapp1
cd testapp1
cargo init --bin
cargo build
cargo run
cargo build
or
cargo build --release
rustup update
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2018-03-29, rust version 1.25.0 (84203cac6 2018-03-25)
info: downloading component 'rustc'
55.2 MiB / 55.2 MiB (100 %) 11.0 MiB/s ETA: 0 s
info: downloading component 'rust-std'
47.3 MiB / 47.3 MiB (100 %) 10.8 MiB/s ETA: 0 s
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: removing component 'rustc'
info: removing component 'rust-std'
info: removing component 'cargo'
info: removing component 'rust-docs'
info: installing component 'rustc'
info: installing component 'rust-std'
info: installing component 'cargo'
info: installing component 'rust-docs'
info: checking for self-updates
info: downloading self-update
stable-x86_64-unknown-linux-gnu updated - rustc 1.25.0 (84203cac6 2018-03-25)
rustup default stable
error: toolchain 'stable-x86_64-unknown-linux-gnu' does not contain component 'rustfmt' for target 'x86_64-unknown-linux-gnu'
# try
rustup toolchain remove stable
rustup toolchain install stable
# then
rustup component add rustfmt
rustup component add rustfmt
cargo fmt
- rustfmt のコンフィギュレーション https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#hard_tabs