-
Notifications
You must be signed in to change notification settings - Fork 2
Add document-unstable
default-feature
#23
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
base: main
Are you sure you want to change the base?
Conversation
Can you please take one step back and describe the problem this solves? I'm missing context here to understand it. |
Sorry for the way too brief PR-description - I updated it and hopefully it now explains the motivation better. Let me know if the description is still lacking details |
No problem. If I had a dollar for every time I'd jumped into a solution assuming that the other person had the context,... I'm going to have to think about this one a bit more, but my initial impression of the solution is that adding a feature flag that all downstream consumers of the library for documentation seems a little heavy. I think that will happen here unless I'm mistaken about how that works. Can you confirm that this approach would break downstream uses of the library? Sometimes speaking in generalities hides the true problem a bit. What actual concrete problems does this cause for you in your daily use. I can see that you're describing the part which you're saying is a problem (inability to turn off generation of docs), but I'd like to see what you're doing that needs this (e.g. what commands are you running, what's the result, and how does this lib cause that). You've sort of alluded to that the json generated is a problem, but I'd like to capture the details a bit more. (This may also surface other alternative solutions). |
This will not break things if
But yes - if users opt out of instability's default feature and don't pass the unstable feature when generating docs they will end up with documentation missing the unstable part of the API (which should be easy to spot). Actual code should never be affected by this change. To illustrate things a bit
With this new feature flag (enabled by default) it would be the same. When adding instability with no-default features enabled ( No rush with this: I was able to work around things, but I guess ideally having a way to opt-out of having unstable API items documented always is useful to other's as well |
What about a I think given that cargo semver checks is making its way into cargo itself, there should be some way to do this, whether its via feature flag/ cfg or some other mechanism. |
I changed this PR to do what Scott suggested. The new cfg is I think it's very unlikely that a user will set this by mistake. I didn't change the original PR description since it would make the conversation so far look weird |
This adds a default feature to include the
cfg(doc)
- this makes it possible to opt-out and generate docs including just the public-API-surface (and helps in using e.g. cargo-semver-checks to check the public API surface)Background
Since #12 the
unstable
macro expands to thisThis is great and nice since documentation generated from this example will include the
something_unstable
function without the need to select theunstable
feature. It's a great default and probably what most users need or want.However, since
rustdoc
unconditionally sets thedoc
config flag it is not possible to generate documentation without the unstable API included.While it's probably a niche use-case to generate docs for the stable API-surface only (most likely just for manual inspection) it becomes more important when using tools for semver-checks (e.g.
cargo-semver-checks
orpublic-api
) - these tools usually rely on generating API-docs in JSON format for further processing and the unstable part of the API shouldn't get checked.The only way I see to accomplish that is to have a way to emit code from the
unstable
macro withoutcfg(doc)
Drawbacks
Features add complexity. If (for some reason) users included
instability
with default-features set tofalse
they will see a difference in the generated documentation.Alternatives
Unfortunately, I don't see any real alternatives since
rustdoc
unconditionally sets thedoc
config.The only (quite hacky) alternative I could think of is to pre-process the generated JSON and remove the unstable parts. Unfortunately, the
rustdoc
JSON format makes this an unpleasant experience especially because we would need to inspect the docs to see if they include a well known pattern. Ideally, I would like to avoid this pre-processing step.Implementation
I think a default-feature which opt-in to including
cfg(doc)
is the most straight-forward way to do this.I am not too confident about the naming of this new feature (i.e. happy to change it) or if you would prefer a non-default feature to opt-out of including
cfg(doc)