Upgrade to Pro — share decks privately, control downloads, hide ads and more …

プログラミング言語Rustのすすめ @TwoGate Tech Meeting

kazzix
December 19, 2020

プログラミング言語Rustのすすめ @TwoGate Tech Meeting

kazzix

December 19, 2020
Tweet

Other Decks in Programming

Transcript

  1. 自己紹介 村田 一真 今年の 3 月あたりからインターン サーバーサイド 信州大学 工学部 3

    年 元長野高専 プログラミング 中 2 ぐらいから 音楽 ギターとかベースとか. 中 2 から 金髪!ピアス! 2
  2. Rust のいいところ 処理系の管理が楽 パッケージマネージャが強い コンパイラが優しい API が使いやすい コーディングルールが気持ちいい コーディング補助(?)がしゅごい 組み込みからフロントまで

    ドキュメントがめっちゃ揃ってる いい感じのエコシステム 強力なマクロ 高速(知らんけど 安全(知らんけど 並列処理強い(知らんけど いろんな環境で使える(知らんけど 9
  3. ライブラリの管理 [dependencies] lazy_static = "1.4" rand = { git =

    "https://github.com/rust-lang-nursery/rand", branch = "next" } [target.'cfg(target_arch = "x86")'.dependencies] native = { path = "native/i686" } [target.'cfg(target_arch = "x86_64")'.dependencies] native = { path = "native/x86_64" } 12
  4. これをコンパイルしようとすると... fn main() { let mut number = 1; let

    number_ref_mut = &mut number; println!("{:?}", number); // ここでエラー println!("{:?}", number_ref_mut); } 17
  5. めっちゃ優しいコンパイラ error[E0502]: cannot borrow `number` as immutable because it is

    also borrowed as mutable --> src/main.rs:6:22 | 4 | let number_ref_mut = &mut number; | ----------- mutable borrow occurs here 5 | 6 | println!("{:?}", number); | ^^^^^^ immutable borrow occurs here 7 | println!("{:?}", number_ref_mut); | -------------- mutable borrow later used here error: aborting due to previous error For more information about this error, try `rustc --explain E0502`. error: could not compile `aaa`. To learn more, run the command again with --verbose. 18
  6. Rust Analyzer IDE 環境を提供する LSP サーバ エディタが IDE みたいになる Cargo

    でインストールできます LSP なので Code でも Vim でも Emacs でも 20
  7. _closure の型は? fn main() { let _closure = || {

    (0..100) .map(|i| i) .filter(|_i| true) .skip(1) .step_by(2) .take(5) }; } 21
  8. 26

  9. 27

  10. 28

  11. /*! こんにちは `cargo doc` !! */ /// この関数は `nya` とプリントします!

    /// /// nya nya nya /// ## Markdown が使えるよ! /// ~~にゃあああ~~ pub fn say_nya(n_nya: u32) { for _ in 0..n_nya { println!("nya"); } } > cargo doc 34
  12. 35

  13. 36

  14. 興味をもったら ブック(チュートリアル的な) https://doc.rust-jp.rs/book-ja/ Slack https://rust-jp.herokuapp.com インストールはたった一行! curl --proto '=https' --tlsv1.2

    -sSf https://sh.rustup.rs | sh Windows の人はここからインストーラを入れてください https://prev.rust-lang.org/ja-JP/other-installers.html 39