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

cmdshelf::from("Swift")

toshi0383
September 05, 2018

 cmdshelf::from("Swift")

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

toshi0383

September 05, 2018
Tweet

More Decks by toshi0383

Other Decks in Programming

Transcript

  1. 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
  2. cmdshelfͱ͸ εΫϦϓτϚωʔδϟʔ, ίϚϯυϥϯφʔ — scriptΛஔ͍ͨgit repoΛremoteͱͯ͠ొ࿥ — cmdshelf run hoge/bar.sh

    ͱ࣮ͯ͠ߦͰ͖Δ — $PATH ͷઃఆ͕ෆཁ σΟϨΫτϦͰωʔϜεϖʔεΛ੾ΕΔ — iOS/tvOSνʔϜؒͷڞ௨scriptӡ༻͕՝୊ͩͬͨ © Toshihiro Suzuki 2018 4
  3. ֎෦ίϚϯυ࣮ߦͷ࣮૷͕͠΍͍͢ ίϚϯυ࣮ߦ͸ 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
  4. CLIϫʔΩϯάάϧʔϓ ! ࠓ೥(2018)3݄ʹΩοΫΦϑ Announcing the CLI Working Group "Command Line

    Application in Rust" (CLAIR) book! (WIP) CLIπʔϧ࣮૷ͷΨΠυϥΠϯ΍υΩϡϝϯτ͕ࡦఆ͞Ε͍ͯ Δɻ ࠓޙͷൃలʹظ଴͕࣋ͯͦ͏ɻ © Toshihiro Suzuki 2018 12
  5. 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
  6. 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
  7. 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