6

I want to use this library: https://github.com/stepfunc/dnp3, but it is not on crates.io, it only has a repository and I can't implement it. I tried to add it to my Cargo.toml like [dependencies] dnp3 = "0.9.1" but it says that it does not exist, and indeed it does not have a crate. Inside the repository, it has some examples in dnp3/example that have use dnp3; as if it were a crate.

How can I use this?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366

3 Answers3

7

You can directly specify a Github (or any other git repository) as the source of the dependency.

[dependencies]
dnp3 = { git = "https://github.com/stepfunc/dnp3" }

See the Cargo reference: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories

SirDarius
  • 41,440
  • 8
  • 86
  • 100
5

You can specify dependencies as Git repositories.

[dependencies]
dnp3 = { git = "https://github.com/stepfunc/dnp3" }

If you want to specify a branch (assuming you do not want to use main/master), you can add a branch key to the declaration above:

[dependencies]
dnp3 = { git = "https://github.com/stepfunc/dnp3", branch = "feature/rustls" }

Related read: Specifying dependencies from git repositories

Carlos Menezes
  • 314
  • 1
  • 8
4

Another way to do it would be to clone the repository and use a dependency with a local path.

[dependencies]
dnp3 = { path = "../dnp3" }

Related rust docs

But of course as other answers mentioned using the git version is better in your case.

Martin W
  • 733
  • 4
  • 12