Rust

unwrap()は変数の所有権を移動させることがある

所有権をわかったつもりだったが、わかってなかった。*1Rust By ExapmpleのPipesの章で、以下のコメントにあるstdinがdropされると記述が信じられなかった。 match process.stdin.unwrap().write_all(PANGRAM.as_bytes()) { Err(why) => panic!("couldn't wr…

Rust By ExampleのFrom and Intoが分かりにくい

The From and Into traits are inherently linked, and this is actually part of its implementation. If you are able to convert type A from type B, then it should be easy to believe that we should be able to convert type B to type A. Rust By E…

forループでイテレータ into_iter() が所有権を奪う

for x in vec と書くと暗黙的に、into_iter()が呼ばれてvecは所有権を失ってしまう。forで暗黙的に呼ぶのなら、所有権を奪わないiter()の方が良かったんじゃないと思い、AI先生に理由を聞いた。どうも、into_iter()が効率がよく、所有権の管理が明確になると…

Rustの勉強を始めた

Rustの勉強をはじめました。もう何年も話題になっているRustに興味を持ったのは、GCCでRustのサポートが進んでいると聞いたからです。 環境設定 mozcのAURではRustが使われているようで、すでに rustup default stable まで実行済みだった。 https://wiki.ar…