Rust Library Development Workflow

When developing a library in Rust (+ Cargo), how do I achieve a quick recompilation / testing cycle?

When developing an application easily, I:

  • Make code changes

  • Switch to the terminal and run cargo run

  • See compiler feedback

But now I want to extract part of my application as a library and publish it on GitHub. I would like to continue developing my application, but now with this library as a dependency. I am going to develop both a library and an application in parallel.

How to get the same fast feedback now?

Both the library and the application will be developed on one computer, I would like to make changes to the library, update the application accordingly and see the feedback from the compiler.

I assume that I could use my library as a dependency in Cargo.toml and run cargo update every time I want to update application dependencies, but it will be somewhat slow because it will need to download the code from github every time and recompile all dependencies.

+6
source share
1 answer

You can use this somewhat undocumented load function. Add the following line to the ~/.cargo/config file (or /path/to/your/binary/project/.cargo/config to limit the effect for your binary project):

 paths = ["/path/to/your/library"] 

Now, each package of the load (or those under /path/to/your/binary/project root), which depends on your library, will use /path/to/your/library as the source code for it, regardless of what indicated in this package manifest, so you can save the git repo url in your program manifest. We hope that this feature will be documented in the future.

Update

This is now described in the Shipping Guide .

+10
source

Source: https://habr.com/ru/post/973653/


All Articles