9
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rustでgithub上のクレートを依存関係に指定する

Posted at

crate.ioに公開されていないrustのクレートをgithubから利用する方法。

Cargo.tomlで指定する

Specifying Dependencies - The Cargo Book
cargoのドキュメントにgithubからもってくる方法が書かれています。

インストールしたいパッケージ名を指定します。
gitにリポジトリのアドレスを値として渡します。
ブランチなどを指定したい場合はそれぞれの指定できます。
{ git = "https://github.com/paritytech/parity-bitcoin.git" branch = <branch name> tag = <tag name> rev = <value>}

Cargo.toml
[dependencies]
keys = { git = "https://github.com/paritytech/parity-bitcoin.git" }

parityのbitcoinライブラリを例にします。
paritytech/parity-bitcoin: The Parity Bitcoin client

これで$ cargo buildすればクレートとしてインストールされます。

インストールされたクレートを利用する

keysクレートを利用します。
extern crate keys;

src/main.rs
extern crate keys;
use keys::generator::Generator;

fn main() {
   let keypair = keys::generator::Random::new(keys::Network::Mainnet); 
   let generated = keypair.generate();
   println!("{}", generated.unwrap())
}

これを実行するとsecp256k1のキーペアを生成してくれます。

9
3
0

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
9
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?