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

Add WorkspaceMember #26

Merged
merged 1 commit into from
Dec 21, 2017
Merged

Conversation

topecongiro
Copy link
Contributor

The implementation of WorkspaceMember is almost identical to PackageId in cargo.
The difference is that its deserialization is simplified and it does not use Arc internally.

Cargo.toml Outdated
@@ -8,6 +8,7 @@ license = "MIT"
readme = "README.md"

[dependencies]
cargo = "0.23"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather be independent from the cargo crate. Can we just use String instead of SourceId for now?

The implementation of WorkspaceMember is almost identical to PackageId in cargo.
The difference is that its deserialization is simplified and it does not use
Arc internally.
@topecongiro
Copy link
Contributor Author

topecongiro commented Dec 21, 2017

Thank you for the review, I replaced SourceId with String.

@oli-obk
Copy link
Owner

oli-obk commented Dec 21, 2017

Ok, so this'll be a breaking change. I'll check whether there are other things I wanted to break and then release a new version

@oli-obk oli-obk merged commit 5d230f5 into oli-obk:master Dec 21, 2017
@oli-obk
Copy link
Owner

oli-obk commented Dec 21, 2017

Published 0.4.0

The only code that breaks (other than WorkspaceMember related one) is code exhaustively matching on the structs.

@oli-obk
Copy link
Owner

oli-obk commented Dec 21, 2017

Maybe we should add a Display impl that reproduces the original String, so anyone who used the workspace_member before can just keep using it by calling to_string()

bors added a commit to rust-lang/cargo that referenced this pull request Jan 15, 2024
fix(metadata): Stabilize id format as PackageIDSpec

### What does this PR try to resolve?

For tools integrating with cargo, `cargo metadata` is the primary interface.  Limitations include:
-  There isn't an unambiguous way to map a package entry from `cargo metadata`  to a parameter to pass to other `cargo` commands.  An `id` field exists but it is documented as an opaque string, useful only for comparisons with other `id`s within the document.
- There isn't an unambiguous way of taking user parameters (`--package`) and mapping them to `cargo metadata` entries.  `cargo pkgid` could help but it returns a `PackageIdSpec` which doesn't exist within the `cargo metadata` output.

This attempts to solve these problems by switching the `id` field from `PackageId` to `PackageIdSpec` which is a [publicly documented format](https://doc.rust-lang.org/cargo/reference/pkgid-spec.html), can be generated by `cargo pkgid`, and is accepted by most commands via the `--package` flag.

As the `"id"` field is documented as opaque, this technically isn't a breaking change though people could be parsing it.

For `cargo_metadata` they do [use a new type that documents it as opaque but publicly expose the inner `String`](https://docs.rs/cargo_metadata/latest/cargo_metadata/struct.PackageId.html).  The `String` wasn't publicly exposed due to a request by users but instead their `PackageId` type replaced using `String`s in the API in oli-obk/cargo_metadata#59 with no indication given as to why the `String` was still exposed.  However, you'll note that before that PR, they had `WorkspaceMember` that parsed `PackageId`.  This was introduced in oli-obk/cargo_metadata#26 without a motivation given.

**Note that `PackageIdSpec` has multiple representation that might uniquely identify a package and we can return any one of them.**

Fixes #7267

### How should we test and review this PR?

### Additional information

cc `@oli-obk`
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

Successfully merging this pull request may close these issues.

2 participants