Cargo metadata and pkgid

cargo metadata returns packages[].id like "sample1 0.1.0 (path+file:///Users/Dev/Workshop/eonil/experiments/rust/sample1)". I have been thought it is a pkgid, but it was not. Cargo does not accept the id expression as a valid pkgid. You can check this behavior like this.

$ cargo build -p "sample1 0.1.0 (path+file:///Users/Dev/Workshop/eonil/experiments/rust/sample1)"
error: cannot parse '///Users/Dev/Workshop/eonil/experiments/rust/sample1)' as a semver

It's confusing that package[].id returned by cargo metadata cannot be used as a package identifier on other cargo commands. Is this an intended behavior? Or am I supposed to break the expression to get proper pkgid?

1 Like

Normally, I think you just use the name (which you get at with packages[].name). But it does seem kind of silly, and I'm pretty sure it's not truly robust that way.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.