Is there a robust way, maybe something in cargo CLI, to get the version of the crate?
I can grep on Cargo.toml, but I'm looking for something that won't break in 6 months.
Is there a better way?
The simplest answer is
cargo pkgid
This outputs
files:///Users/sus/code/project#0.1.0
If you want this as just the version part, you can pipe this to cut
(or handle it yourself in your programming language of choice)
cargo pkgid | cut -d "#" -f2