How can I use a library that is not on crates.io?

Viewed 788

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?

3 Answers

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

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.

Related