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

3

7

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?

Lomax answered 24/9, 2021 at 14:53 Comment(0)
O
11

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 on specifying dependencies from git repositories.

Oral answered 24/9, 2021 at 14:59 Comment(2)
Thank you! I will try it right nowLomax
thanks a lot! It worked perfect, from now on I will read the documentation betterLomax
P
6

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

Paynim answered 24/9, 2021 at 15:4 Comment(0)
P
5

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.

Pyrazole answered 25/9, 2021 at 20:7 Comment(1)
this is also very useful! Thank you so muchLomax

© 2022 - 2024 — McMap. All rights reserved.