Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better representation for Source #268

Open
antonok-edm opened this issue Nov 1, 2024 · 1 comment
Open

Better representation for Source #268

antonok-edm opened this issue Nov 1, 2024 · 1 comment

Comments

@antonok-edm
Copy link

Source is currently represented as a String, and the documentation says:

It is possible to inspect the repr field, if the need arises, but its precise format is an implementation detail and is subject to change.

This is slightly problematic for users of the crate who would inspect this field for the purpose of e.g. downloading the relevant crate. There is already Source::is_crates_io, but other types of sources require custom code to identify and even more custom code to parse out the details relevant to downloading, all of which could be prone to silent breakage if the internal format is updated.

Ideally, Source could have a type-safe representation, like an enum over CratesIo, Git, Path, or Registry. Each variant could provide accessors for relevant details, e.g. The Git variant could provide accessors for the commit reference and a downloadable repo URL.

@weihanglo
Copy link
Contributor

Ideally, Source could have a type-safe representation, like an enum over CratesIo, Git, Path, or Registry. Each variant could provide accessors for relevant details, e.g. The Git variant could provide accessors for the commit reference and a downloadable repo URL.

For kinds of sources, it is possible to provides such methods, as in the doc of cargo metadata explicitly states that the protocol prefix e.g. git+, registry+. For providing additional information like Git repo URL you mentioned, it is deemed opaque to cargo_metadata crate. Everything after is the prefix is subject to change.

The value after the + is not explicitly defined, and may change
between versions of Cargo and may not directly correlate to other
things, such as registry definitions in a config file. New source
kinds may be added in the future which will have different +
prefixed identifiers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants