自分用メモ。
開発環境
インストール
apt install とかはできないぽい。
curl https://sh.rustup.rs -sSf | sh
このスクリプトの出力の通りだが、~/.rustup と ~/.cargo が作られる。cargo、rustc、rustup などのコマンドは ~/.cargo/bin にあるのでそこにPATHを通す必要があるが、勝手にやってくれる。
rustup self uninstall でこれらをアンインストールできるらしい。
cargo
プロジェクト作成
cargo init
cargo new xxx --bin とかでもいいらしい。--binはbinaryを作るcrateであることを示すフラグ。cargo initでもbinaryを作るように生成されるように見える。
実行
cargo run
で走らせられる。cargo run -- argsでコマンドライン引数を渡せるぽい。
ビルド
cargo build
でバイナリを作れる。cargo build では target/build/xxx にでき、cargo build --release では target/release/xxx にできる。
言語仕様
into()
Into<T> traitを実装していればinto()が使えるという感じぽい。
pub trait Into<T> {
fn into(self) -> T;
}
ただし、
One should avoid implementing Into and implement From instead. Implementing From automatically provides one with an implementation of Into thanks to the blanket implementation in the standard library.
実際には From<T> を実装することが期待されている模様。
pub trait From<T> {
fn from(T) -> Self;
}
$foo
$foo は macro_rules! の引数で使われる。
The arguments of a macro are prefixed by a dollar sign $ and type annotated with a designator: