Search code examples
rustrust-cargocratednp3

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


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?


Solution

  • 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