How to clone rust library, change it and then use it in my own project

Viewed 180

I want to clone the tokio library and make a few changes to it, then use it in another project, just like I would if I had specified tokio as a dependency in my Cargo.toml.

How would I go about doing that?

2 Answers

You could use a path dependency for this. Paths are interpreted as relative to the Cargo.toml they appear in, so you have a few options:

Have your tokio fork as a subdirectory tokio in your project, or symlinked there:

[dependencies]
tokio = { path = "tokio" }

Have your tokio fork live somewhere else in your home directory:

[dependencies]
tokio = { path = "/home/youruser/tokio-fork" }

Or wherever else makes the most sense for you.

As an alternative, if instead of local dev, you want to use git, you could fork the repo an use reference it:

tokio = { git = "https://github.com/your-user/tokio" }

Take a look at the documentation on how to specify dependencies

Related