cmdshelf::from("Swift")

E2c86baa99178b8400a2ef49ef861a6c?s=47 toshi0383
September 05, 2018

 cmdshelf::from("Swift")

RustのLT会! Rust入門者の集い #5 の発表資料です。
https://rust.connpass.com/event/92821/

E2c86baa99178b8400a2ef49ef861a6c?s=128

toshi0383

September 05, 2018
Tweet

Transcript

  1. Swi!Ͱॻ͍ͨCLIπʔϧΛRustͰ ॻ͖௚͠·ͨ͠ RustͷLTձʂ Rustೖ໳ऀͷू͍ #5 Sep 5, 2018 Toshihiro Suzuki

    © Toshihiro Suzuki 2018 1
  2. whoami ླ໦ ढ़༟ (@toshi0383 / τογʔ) 2011- SRAͱ͍͏ձࣾ UnixͰJava 2014-

    ωΫετεέʔϓͱ͍͏ձࣾͰiOSσϏϡʔ, DRMΤʔδΣϯτSDK΋ͪΐͬͱ͚ͩܦݧ. 2017- AbemaTV join. iOSDCͰLTͨ͠ΓɺtvOSΞυϕϯτΧϨϯμʔओ࠵ͨ͠Γ. 2018- ಈըμ΢ϯϩʔυػೳΛ࣮૷. ݱࡏ͸ετϦʔϛϯάΫϥΠΞϯτνʔϜͰಈըࢹௌମݧ޲্ ศརͳπʔϧΛ࡞ͬͯ։ൃΛޮ཰Խ͢Δͷ͕झຯ ϨʔγϯάΧʔτܦݧऀ, GT SPORT, F1 Rustྺ1ϲ݄͘Β͍ (ॳ৺ऀͰ͢ʂ) © Toshihiro Suzuki 2018 2
  3. Swi!Ͱॻ͍͍ͯͨπʔϧ cmdshelf © Toshihiro Suzuki 2018 3

  4. cmdshelfͱ͸ εΫϦϓτϚωʔδϟʔ, ίϚϯυϥϯφʔ — scriptΛஔ͍ͨgit repoΛremoteͱͯ͠ొ࿥ — cmdshelf run hoge/bar.sh

    ͱ࣮ͯ͠ߦͰ͖Δ — $PATH ͷઃఆ͕ෆཁ σΟϨΫτϦͰωʔϜεϖʔεΛ੾ΕΔ — iOS/tvOSνʔϜؒͷڞ௨scriptӡ༻͕՝୊ͩͬͨ © Toshihiro Suzuki 2018 4
  5. ઌि·ͰSwi! (ͱC) Ͱ͕ͨ͠.. © Toshihiro Suzuki 2018 5

  6. RustʹແࣄҠߦ׬ྃ͠·ͨ͠ ! © Toshihiro Suzuki 2018 6

  7. ͳͥRustʹҠߦͨ͠ͷ͔ ʮͦΕͳΓʹStar ⭐ ΋͍͖ͭͯͨ͠ɺͦΖͦΖͪΌΜͱcross- platformରԠ͍ͨ͠ͳʔʯ — Swiftͩͱ΄΅AppleΤίγεςϜͰ͔͠ಈ͔ͳ͍ɻ — Swift͸ΤίγεςϜతʹCLIπʔϧॻ͘ͷʹ޲͍ͯͳ͍ؾ͕ ͖ͯͨ͠ɻ(ޙड़)

    ݸਓతʹΑ͘࢖͍ͬͯΔ sharkdp/fd ͕RustͰॻ͔Ε͍ͯͯɺ લ͔ΒRust࢖ͬͯΈ͍ͨͱࢥ͍ͬͯͨɻ © Toshihiro Suzuki 2018 7
  8. ࣮ࡍʹRustͰॻ͍ͯΈͯΑ͔ͬͨ ͱ͜Ζ © Toshihiro Suzuki 2018 8

  9. (ୈҰҹ৅) Cargo.toml؆ܿͰྑͦ͞͏ɻ Package.swift, build.gradle, Fastfile ͳͲɺߴػೳͳઃఆ ϑΝΠϧʹ͸ίʔυΛॻ͍ͯ͠·͍ෳࡶԽ͕ͪ͠ɻ ͦΕ͕Ͱ͖ͳ͍ͷ͕ྑͦ͞͏ɻ > Why

    cargo use toml? > It's basically the least terrible option © Toshihiro Suzuki 2018 9
  10. ֎෦ίϚϯυ࣮ߦͷ࣮૷͕͠΍͍͢ ίϚϯυ࣮ߦ͸ cmdshelf ʹͱͬͯ͸৺ଁ෦෼ std::process::Command let output = if cfg!(target_os

    = "windows") { Command::new("cmd") .args(&["/C", command]) .output() } else { Command::new("sh") .arg("-c") .arg(command) .output() }; © Toshihiro Suzuki 2018 10
  11. Swi!ͩͱ࣮͸͜ͷล͕Ұ൪ͭΒ͍ Foundation͔ΒPOSIXܥͷAPI͕͍ͭͷؒʹ͔Ұ෦remove͞ Ε͍ͯͨࣄ݅ɻFoundation.ProcessΛ࢖͑ͱͷ͜ͱɻ Foundation.Process͸ΠϯλʔϑΣʔε͕Θ͔ΓͮΒ͘ඪ४ ೖग़ྗͷڍಈΛҙਤ௨Γ࣮૷Ͱ͖ͣɺ݁ہpopen΍pcloseΛC Ͱ࠶࣮૷ ! © Toshihiro Suzuki

    2018 11
  12. CLIϫʔΩϯάάϧʔϓ ! ࠓ೥(2018)3݄ʹΩοΫΦϑ Announcing the CLI Working Group "Command Line

    Application in Rust" (CLAIR) book! (WIP) CLIπʔϧ࣮૷ͷΨΠυϥΠϯ΍υΩϡϝϯτ͕ࡦఆ͞Ε͍ͯ Δɻ ࠓޙͷൃలʹظ଴͕࣋ͯͦ͏ɻ © Toshihiro Suzuki 2018 12
  13. CLI Dev UX͕ྑͦ͞͏ © Toshihiro Suzuki 2018 13

  14. CLIπʔϧ։ൃऀ໨ઢͰͷSwi!ͱͷൺֱ(׬શʹओ؍) ػೳ Swi! Rust ։ൃ؀ڥ Xcode, vim vim ύοέʔδ؅ཧ SwiftPM

    Cargo ύοέʔδఆٛ Package.swift Cargo.toml ઃఆϑΝΠϧ yml toml(?) ύοέʔδϚωʔδϟͷman ϖʔδαϙʔτ ͳ͍͢͠Δؾ΋ͳͦ͞͏ ͳ͍͚Ͳrfcͱͯٞ͠࿦͞Εͯ ͍Δ ֎෦ίϚϯυ࣮ߦ Foundation.Process or ඇਪ ঑ͳPOSIX API(ڪා) std::process::Command © Toshihiro Suzuki 2018 14
  15. ࣮૷ͰϋϚͬͨͱ͜Ζ © Toshihiro Suzuki 2018 15

  16. τϨΠτΦϒδΣΫτฦͤ·ͤΜ໰୊ — impl Runnable ฦͤ·ͤΜʂ — Box<Runnable + 'static> ͳΜͩ͜Ε

    © Toshihiro Suzuki 2018 16
  17. String ͷlifetime parameter? pub struct CommandEntry<'a> { pub remote: &'a

    str, pub fullpath: String, pub path: &'a str, // fullpathͷҰ෦ } ॳظԽ࣌ʹ fullpath ͱ path ͷੜଘظؒΛඥ͚ͮΔ͜ͱ͕Ͱ ͖ͣίϯύΠϧ௨Βͣ ! © Toshihiro Suzuki 2018 17
  18. String ͷlifetime parameter? ຖճܭࢉͤͯ͞ճආ pub struct CommandEntry<'a> { pub remote:

    &'a str, pub fullpath: String, } impl<'a> CommandEntry<'a> { pub fn path(&self) -> &str { ... } } ͍͍ํ๏͋Ε͹ͥͻڭ͍͑ͯͩ͘͞ © Toshihiro Suzuki 2018 18
  19. ٤ۓͷ՝୊ © Toshihiro Suzuki 2018 19

  20. ٤ۓͷ՝୊ ΫϩεϓϥοτϑΥʔϜରԠ © Toshihiro Suzuki 2018 20

  21. ٤ۓͷ՝୊ ΫϩεϓϥοτϑΥʔϜରԠ Windows࣋ͬͯͳ͍͠ɺmacOSҎ֎΄ͱΜͲ৮ͬͨ͜ͱͳ ͍ɻ Έͳ͞ΜͲ͏ͯ͠Δͷʁ © Toshihiro Suzuki 2018 21

  22. ಉٙ͡໰Λ͍࣋ͬͯΔਓ͕ͨ·ͨ·CLI-WGͷGi!erͰ࣭໰͠ ͯͨ © Toshihiro Suzuki 2018 22

  23. CLI-WGతʹ͸ͪ͜ΒͰٞ࿦͞Ε͍ͯΔ໛༷ɻ - rust-lang-nursery/cli-wg#8 ͱΓ͋͑ͣ japaric/trust Ͱ֤ϓϥοτϑΥʔϜ޲͚ͷόΠφ Ϧ͸࡞Εͦ͏ʁ © Toshihiro Suzuki

    2018 23
  24. ഑෍Ҏલʹ ϑΝΠϧύε۠੾จࣈͷߟྀ๨Εͯͨ path.split("/") => ࡢ೔ରԠ͠·ͨ͠ɻ ଞʹ΋͍Ζ͍ΖରԠඞཁͳͷ͔΋ɻ © Toshihiro Suzuki 2018

    24
  25. summary — Rust͸CLIπʔϧͷDev UX͕ྑͦ͞͏ɻ — ൃද·ͰʹҠߦؒʹ߹ͬͯΑ͔ͬͨɻ — ϓϧϦΫ׻ܴɻಛʹɺ৽ϩΰඳ͍ͯ͘ΕΔਓืू © Toshihiro

    Suzuki 2018 25
  26. Toshihiro Suzuki ! Twitter: @toshi0383 GitHub: @toshi0383 Qiita: @toshi0383 Email:

    t.suzuki326@gmail.com © Toshihiro Suzuki 2018 26