Automatically replace `'*'` in Cargo.toml with latest/current version?


#1

When I’m hacking on my little project, I usually just use somedep = '*'. I wish it automatically turned into the latest version or something like that. Is there any tool to do that?


#2

For vs code there is an extension called crates that prints the latest version next to the dependency, and also allows you to choose from existing versions.
https://marketplace.visualstudio.com/items?itemName=serayuzgur.crates


#3

That’s neat. But I’m a vimer, I really care only about getting rid of * there quickly. :slight_smile:


#4

the ‘cargo edit’ and ‘cargo update’ plugins, probably does what you want. Add with the current version easily, and update as you go.


#5

I might be missing something, but they don’t seem to do what I want. I want '*' to be replaced with '0.4.2' in Cargo.toml, not just get new deps in Cargo.lock


#6

Sorry, two clarifications:

  • I understood what you wanted; I was suggesting an alternate workflow (where you never start with the *) that might achieve the same effect (not really caring about the actual value to start with, because cargo add just puts it there for you), but that wasn’t clear.
  • I should have talked about cargo upgrade rather than cargo update; they’re easy to mix up.