LoginSignup
2
1

More than 3 years have passed since last update.

[Rust] Cargo.toml の dependencies に記載するバージョンの探し方

Last updated at Posted at 2019-12-23

結論

  • https://crates.io/crates/reqwest からコピペする
    • @sinkuu さんに教えていただきました。ありがとうございます :pray:
  • https://docs.rs/crate/{crate名}Versions から選択する

直面した問題

  • reqwest (https://docs.rs/reqwest) を利用したいが cargo install reqwest を実行しても失敗する
    • error: specified package `reqwest v0.9.24` has no binaries が出力される

対応

なぜerrorになるのか

  • https://doc.rust-lang.org/cargo/commands/cargo-install.html
  • This command manages Cargo’s local set of installed binary crates. Only packages which have executable [[bin]] or [[example]] targets can be installed, and all executables are installed into the installation root’s bin folder.
    • google翻訳 このコマンドは、Cargoのインストール済みバイナリクレートのローカルセットを管理します。実行可能な[[bin]]または[[example]]ターゲットを持つパッケージのみをインストールでき、すべての実行可能ファイルはインストールルートのbinフォルダーにインストールされます。
  • reqwestはbinターゲットを持つパッケージでないから
  • npm install のノリではダメらしい
  • Cargo.tomlのdependenciesに追記する必要がある

Cargo.toml にどう書くか

crates.ioでの探し方

  • 例えばreqwestであれば https://crates.io/crates/reqwest にCargo.tomlの記載方法が書いてあるのでコピペする
    • @sinkuu さんに教えていただきました。ありがとうございます :pray:

doc.rsでの探し方

  • reqwest でググると https://docs.rs/reqwest/0.10.0-alpha.2/reqwest/ が上位にhitする(2019.12.23現在)
    • ググラビリティが高くて素晴らしい
  • 上記ページを開いてもdependenciesにどう書けばいいか載っていない
  • スクリーンショット_2019-12-23_21_09_20.png
  • 上画像の赤枠をクリックすると https://docs.rs/crate/{crate名} に遷移する
  • 左カラムにバージョン一覧( Versions )があるのでそこから選択してCargo.tomlに書くと利用できる
    • 例: reqwest = "0.9.24"
  • 自分の環境では ~/.cargo/registry/src/github.com-{ハッシュ}/reqwest-0.9.24 にダウンロードされていた
2
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1