Rust
Rust is programming language
Rust basic
Writing An Interpreter In Rust して、Wasm で動かしてみた - wadackel.me
Learn Rust Programming Course – Interactive Rust Language Tutorial on Replit
why rust
The Rust Programming Language Forum
rust book stable
The Epic Story of Dropbox's Exodus From the Amazon Cloud Empire | WIRED #dropbox
Yet Another Bioinformatic blog #bioinfomatics
https://www.rerun.io/blog/why-rust
Rustで高速な標準出力 | κeenのHappy Hacκing Blog
visvirial/sccache-action: A GitHub Action that speeds up Rust compilation with sccache.
http://blog.pnkfx.org/blog/2015/10/27/gc-and-rust-part-0-how-does-gc-work/ #gc
take in std::mem - Rust
unit test で stdout
cargo test -- --nocapture
install
rustup使うのがいいみたい
$ rustup update stable
rustup -> rustc -> cargoみたいな感じで全部はいるのかな?
Toolchains - The rustup book
開発スタート
First Steps with Cargo - The Cargo Book
cargo
toolchains
cargo +nighty build
fromstring/ from
parse/intoメソッドがつかえるようになったりする
exit
std::process::exit(0x0100);
rls
https://github.com/rust-lang/rls/issues/1273
vscode
所有権はどこにあるのか、参照なのか、に気をつけるとよさげ
tools
nannou
https://github.com/google/evcxr/blob/master/README.md
[update https://doc.rust-lang
std::process::Command
プロセスを作成
https://keens.github.io/blog/2016/12/02/rustnopurosesu/
tuple
let tup: [型; サイズ] = (x, y, z)
rustでは初期化せずに宣言はできない?
(V; N)で値がVでN要素のtuple
異なる型をグループにできる
アクセスは '.'で
array
長さを変えられない
変更したくない値を入れておく
長さ以上のindexにアクセスすると、処理をしない。言語によっては間違ったメモリにアクセスすることもあるらしい。/ https://doc.rust-lang.org/book/2018-edition/ch03-02-data-types.html#invalid-array-element-access
statementは値を返さない
;がついている。文。
したがって x = y = 1のような書き方は不可
値を返すのはexpression
semicolonなし
{}はexpressionなので最後のexpressionの値を返す。
ifもexpression
ownership
Rust ownership
所有権と借用について - Qiita
所有権の移動に関して許されるのは「Ownerが、貸与中でないオブジェクトの所有権を移動すること」だけである。Ownerが、貸与中オブジェクトの所有権を移動することはできないし、また、Borrowerが、借用中オブジェクトの所有権を勝手に移動することもできない。
key feature
memory management
スコープから外れたときに自動的ににメモリーを開放する=drop
referenceしたとき=borrowしたときはownershipは持たない=スコープから抜けてもdropしない。
さらに、変数を変更できない。
mutable referenceも可能だが、一つしか存在し得ない
文字列リテラルは変更できないが文字列型の変数は可能
リテラルはメモリ上に固定されるため
だから早い
Stringは配列への参照
mutable 参照はスコープ内でひとつ
https://doc.rust-lang.org/book/2018-edition/ch04-02-references-and-borrowing.html#mutable-references
mutable refとrefは同時にだめ。
ヒープはmoveされて前の変数(ポインタ)は無効になるがスタックはshallow copyだから無効にはならない
https://doc.rust-lang.org/book/2018-edition/ch04-02-references-and-borrowing.html#mutable-references
参照先がない参照の防止
struct
値のグループ
クラスみたいなもの
値を意味にまとめる
デバッグ => #[derive(Debug)]
親構造体がmutなら子もmut
https://gist.github.com/kanna0000/e379bff7eba948dba3340d6742fb7948
modules
https://doc.rust-lang.org/book/2018-edition/ch07-01-mod-and-the-filesystem.html#rules-of-module-filesystems
モジュールも関数も意図的にpublicにする必要あり。
10. Generic Types, Traits, and Lifetimes
関数でlifetime annotationつけたら短い方にそろう
trais bounds
Amazon.co.jp:カスタマーレビュー: プログラミングRust
「bound」の訳について · Issue #153 · rust-lang-ja/the-rust-programming-language-ja
デスクトップアプリ
https://github.com/Boscop/web-view