-
Notifications
You must be signed in to change notification settings - Fork 96
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 support for package.metadata table #37
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test doesn't work on stable yet. Is there a way to conditionally execute the test only on nightly and beta?
There should be env vars in travis.
Is it ok to expose types of the serde_json dependency in the public API? Or do we need to make the serde_json dependency public?
Maybe we could make the field generic. If it's generic the user can choose their own metadata type instead of having to get their data from a serde map.
For backwards compat you could rename all generic types to GenericFoo
or sth and reexport via type Foo = GenericFoo<()>;
or type Foo = GenericFoo<json::Map<String, serde_json::Value>>;
no need to reexport serde_json, bumping to a potential 2.0 would require a version bump anyway.
src/lib.rs
Outdated
@@ -155,6 +155,8 @@ pub struct Package { | |||
pub features: HashMap<String, Vec<String>>, | |||
/// Path containing the `Cargo.toml` | |||
pub manifest_path: String, | |||
/// Contents of the free form package.metadata section | |||
pub metadata: Option<serde_json::Map<String, serde_json::Value>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be an Option
? Can't it simply be an empty table? I don't want to distinguish between no table and an empty table. That feels like noise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An empty table doesn't parse if the key is not present. But I pushed a new version that makes the field a serde_json::Value
(null if not present).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried #[serde(default)]
on the metadata
field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the metadata field is always present and null
if not set. serde(default)
fails in this case. So I think serde_json::Value
is the correct type here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But serde(default)
helps that no “missing field metadata
” error occurs on stable.
Ok. Should I add an
Sounds like a good idea, but I'm not quite sure if this would work with multiple packages. The |
just put it in the test, maybe with a nice error message if the condition is not set, so users running locally know what's going on.
oh god. yea let's not do anything here. Just store the json and maybe provide an example in the readme showing how to deserialize that into a custom structure. |
I added a “NOTE: This test currently only works on the beta and nightly channel.” error message and a short example how to transform a |
Thanks! Could you release a new version to crates.io? |
I do have a deskop open for it and even ran |
published as v0.5.5 |
Thanks! |
Since rust-lang/cargo#5360
cargo metadata
outputs the contents of the optionalpackage.metadata
table. This PR adds support for the table to this crate. Since the table can contain arbitrary content, the return type is a dynamicserde_json::Map
.Unresolved questions:
serde_json
dependency public?