简体   繁体   中英

Rust library development workflow

When developing a library in Rust (+ Cargo), how do I achieve the fast recompile/test cycle?

When developing an app, it's easy, I:

  • Make changes in the code

  • Switch to the terminal and run cargo run

  • See the compiler feedback

But now I want to extract parts of my app as a library and publish it on GitHub. I would like to continue developing my app, but now with this library as a dependency. I'm going to develop both the library and the app in parallel.

How do I get same quick feedback now?

Both the library and the app will be developed on the same machine, I would like to make changes to the library, update the app correspondingly and see the compiler feedback.

I'm guessing I could use my library as a dependency in Cargo.toml and run cargo update each time I want to update my app's dependencies, but this will be somewhat slow because it will have to download the code from github each time and recompile all dependencies.

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

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

From now on every cargo package (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 is specified in this package manifest, so you can keep Git repo URL in your program manifest. Hopefully this feature will be documented in future.

Update

This is now documented in the Cargo guide .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM