## 背景 - [[Slack]]で『特定投稿の集合をchannelごとにグルーピングした結果を知りたい』というオーダーがあった - 具体的には特定日の自分が絡む投稿 (多分) ## おさらいとキャッチアップのポイント - 非同期通信処理 - [[macOS]]での動作環境 - [[Slack]]の[[OAuth 2.0]] ## TODO - [x] [[WSL2]]の[[Ubuntu]]環境で[[Rust]]を動かしてみる - [x] [[Rust]]に関するツールのインストール - [x] ローカルでプロジェクト作成 - [x] [[asdf]]による[[Rust]]をアンインストール - [x] 公式サイトから[[Rust]]をインストール - [x] ローカルでプロジェクト作成 - [x] [[Neovim]]からHello Worldを出力する - [x] [[🧊Vigilancia]]からSlack clientを移植して動かしてみる - [x] [[serde]] [[serde_json]] [[reqwest]] [[anyhow]]のインストール - トークンはローカルのベタでOK ([[🧊Vigilancia]]からぱくる) - [x] [[pkg-config]]インストール - [x] [[Cargo.toml]]にfeatureとかを書き換え - [x] main関数でawait構文を使えるようにする - [x] `search_message`が動くこと - [x] 非同期runtime周り - [x] トークンは環境変数からとる - [x] dotenvから読み込む - [x] channel名を表示する (⏲️02:00:33) - [ ] [[GitHub]]にリポジトリを作成する - [ ] [[GitHub Actions]]でリリースできるようにする - [ ] [[OAuth 2.0]]を通して毎回トークンを発行する (できれば) - [ ] [[macOS]]で動作を確認してもらう ## メモ ```console $ asdf plugin-add rust https://github.com/asdf-community/asdf-rust.git $ asdf install rust latest asdf install rust latest ∗ Downloading... ∗ Installing... install: creating uninstall script at /home/tadashi-aikawa/.asdf/installs/rust/1.72.1/lib/rustlib/uninstall.sh install: installing component 'rustc' install: installing component 'rust-std-x86_64-unknown-linux-gnu' install: installing component 'rust-docs' install: installing component 'rust-docs-json-preview' install: installing component 'rust-demangler-preview' install: installing component 'cargo' install: installing component 'rustfmt-preview' install: installing component 'rls-preview' install: installing component 'rust-analyzer-preview' install: installing component 'llvm-tools-preview' install: installing component 'clippy-preview' install: installing component 'rust-analysis-x86_64-unknown-linux-gnu' install: WARNING: failed to run ldconfig. this may happen when not installing as root. run with --verbose to see the error rust installed. The installation was successful! $ asdf global rust latest $ cargo --version cargo 1.72.1 (103a7ff2e 2023-08-15) $ rustc --version rustc 1.72.1 (d5c2e9c34 2023-09-13) $ cargo new ruslack Created binary (application) `ruslack` package ``` [[Neovim]]で起動するとエラーが... ```error Failed to spawn one or more proc-macro servers. - cannot find proc-macro-srv, the workspace `/home/tadashi-aikawa/git/github.com/tadashi-aikawa/ruslack` is missing a sysroot Failed to find sysroot for Cargo.toml file /home/tadashi-aikawa/git/github.com/tadashi-aikawa/ruslack/Cargo.toml. Is rust-src installed? can't load standard library from sysroot /home/tadashi-aikawa/.asdf/installs/rust/1.72.1 (discovered via `rustc --print sysroot`) try installing the ``` [[asdf]]経由のインストールが怪しいので公式推奨のやり方に変更する。まずはアンインストール。 ```console asdf uninstall rust asdf plugin remove rust ``` https://www.rust-lang.org/ja/tools/install より ```console $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh info: downloading installer Welcome to Rust! This will download and install the official compiler for the Rust programming language, and its package manager, Cargo. Rustup metadata and toolchains will be installed into the Rustup home directory, located at: /home/tadashi-aikawa/.rustup This can be modified with the RUSTUP_HOME environment variable. The Cargo home directory is located at: /home/tadashi-aikawa/.cargo This can be modified with the CARGO_HOME environment variable. The cargo, rustc, rustup and other commands will be added to Cargo's bin directory, located at: /home/tadashi-aikawa/.cargo/bin This path will then be added to your PATH environment variable by modifying the profile files located at: /home/tadashi-aikawa/.profile /home/tadashi-aikawa/.bashrc You can uninstall at any time with rustup self uninstall and these changes will be reverted. Current installation options: default host triple: x86_64-unknown-linux-gnu default toolchain: stable (default) profile: default modify PATH variable: yes 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation > info: profile set to 'default' info: default host triple is x86_64-unknown-linux-gnu info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' info: latest update on 2023-09-19, rust version 1.72.1 (d5c2e9c34 2023-09-13) info: downloading component 'cargo' 7.9 MiB / 7.9 MiB (100 %) 2.2 MiB/s in 3s ETA: 0s info: downloading component 'clippy' info: downloading component 'rust-docs' 13.7 MiB / 13.7 MiB (100 %) 3.0 MiB/s in 4s ETA: 0s info: downloading component 'rust-std' 26.9 MiB / 26.9 MiB (100 %) 2.4 MiB/s in 11s ETA: 0s info: downloading component 'rustc' 64.2 MiB / 64.2 MiB (100 %) 1.6 MiB/s in 38s ETA: 0s info: downloading component 'rustfmt' 2.5 MiB / 2.5 MiB (100 %) 1.9 MiB/s in 1s ETA: 0s info: installing component 'cargo' info: installing component 'clippy' info: installing component 'rust-docs' 13.7 MiB / 13.7 MiB (100 %) 13.1 MiB/s in 1s ETA: 0s info: installing component 'rust-std' 26.9 MiB / 26.9 MiB (100 %) 20.3 MiB/s in 1s ETA: 0s info: installing component 'rustc' 64.2 MiB / 64.2 MiB (100 %) 22.5 MiB/s in 2s ETA: 0s info: installing component 'rustfmt' info: default toolchain set to 'stable-x86_64-unknown-linux-gnu' stable-x86_64-unknown-linux-gnu installed - rustc 1.72.1 (d5c2e9c34 2023-09-13) Rust is installed now. Great! To get started you may need to restart your current shell. This would reload your PATH environment variable to include Cargo's bin directory ($HOME/.cargo/bin). To configure your current shell, run: source "$HOME/.cargo/env" ``` ```console $ cargo --version cargo 1.72.1 (103a7ff2e 2023-08-15) $ rustc --version rustc 1.72.1 (d5c2e9c34 2023-09-13) $ rm -rf ruslack $ cargo new ruslack Created binary (application) `ruslack` package ``` ```console cargo add serde serde_json reqwest anyhow ``` ``` [dependencies] anyhow = "1.0.75" reqwest = "0.11.22" serde = "1.0.188" serde_json = "1.0.107" ``` 非同期リクエストには[[tokio]]も恐らくいる。 ``` [dependencies] tokio = { version = "1", features = ["full"] } ```