-
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
Provide higher-level API around a Package
's features?
#279
Comments
Yea I like this. There are various other high level APIs I want to figure out. In ui_test I'm ad-hoc implementing various ways to search and filter deps |
Just curious, why not use an enum like cargo does? |
We probably should do that, indeed! I didn't want to spend too much time looking into (/coding up) the details before checking if such an API would actually be welcome. |
As another interested user (for The upcoming release of In principle, it would even be useful to know "what is the full set of transitively-enabled features from enabling feature X." This requires a traversal of the feature graph, which isn't that hard to implement but it would be nice if we didn't all have to maintain our own copies. One canonical well-tested implementation in |
@obi1kenobi while this is wasn't the motivation behind my interest in a richer features API, now that you mention it I would actually need such a functionality later on as well! 👍🏻 |
After having done some further exploration today I've come to the conclusion that a visitor API would probably be the most flexible, for which I've just opened a draft PR at #281 |
Before opening a PR for this I wanted to first check if such a change would be aligned with your vision of this crate, @oli-obk.
Motivation
With the transitive required features of a package encoding semantic information (weak vs. strong, dep vs. feature, transitive vs. non-transitive etc.) these days it feels like
cargo_metadata
should provide a fail-safe and higher-level API for that, rather than expecting users to manually perform pattern matching on the bare string representation, potentially fragmenting the ecosystem in the long-term due to subtle bugs downstream.Draft implementation
Edit: See update here: #279 (comment)
Outdated implementation
Change the following member of
Package
:Introduce a new-type around the map's value type, that could look something like this:
Correctness
Afaict the implementation provided above should be correct.
That said for implicit dependencies the result might be unexpected (yet technically correct, I think), since a
FeatureDep
instance cannot locally reason about whether or not it is an implicit dependency feature, without access to the set of package's features (and dependencies). (I shortly looked into wrapping the wholeBTreeMap<…>
in aPackageFeatures
new-type, but the changes required for this felt disproportionate to the benefit of addressing this one edge-case that's already being phased-out.)But that's arguably the fault of the (since deprecated) implicit features themselves, and not an issue with this particular implementation. And given that are already effectively deprecated and scheduled for removal in the next edition (afaict?) this feels like an acceptable edge-case?
What do you think about the general direction?
The text was updated successfully, but these errors were encountered: