How to use my own crate

It really depends on how public your project is. In general, you will just depend on it in your program's Cargo.toml, and access it with extern crate <name>; just like a library from crates.io.

If your crate is published in a github repository (or on any other public git server), you can depend on it in Cargo.toml with:

[package]
# ...

[dependencies]
# ...
my_crate_name = { git = "https://github.com/username/project-name.git" }

If your project isn't on github, you can depend on it with a path dependency:

[dependencies]
# ...
my_crate_name = { path = "../my-crate-directory" }

You can adjust the path element to point directly to the directory your crate is in.


After you've depended on your crate in Cargo.toml, you can use it in your program with extern crate:

// my-program/src/main.rs
extern crate my_crate;

fn main() {
   let x = my_crate::a_function();
}