Since cargo doesn’t support post build scripts, I’m running cargo in a Makefile to compile my project and run scripts afterwards. One of the steps involved is moving the target binaries which requires the name of the crate. However, at the moment there doesn’t seem to be a straightforward way to get a name of the current crate. Currently, two options are either parsing the Cargo.toml file or running cargo pkgid and parsing the Package ID spec.
Since pkgid already keeps name, version and url in the PackageIDSpec struct internally and those fields are also available to regular build scripts (in the form of environment variables), it would be useful for external tools if additional flags were added to the pkgid command to only retrieve one of the components of the spec. This could be implemented by e.g. mutually exclusive --name, --version and --url flags which print the respective parts of the spec to stdout.