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

Enumerate the circumstances in which private in public is acceptable #73

Closed
dtolnay opened this Issue May 27, 2017 · 4 comments

Comments

Projects
None yet
1 participant
@dtolnay
Copy link
Member

dtolnay commented May 27, 2017

In serde_json::value::Index there is a private supertrait to seal the trait and allow it to evolve as needed. This is an acceptable use.

In reqwest::RedirectPolicy::custom the RedirectAttempt from the function signature is private, which forces the user to express their redirect policy as a closure. There is no way they can factor it out into a function. This seems unnecessary.

@dtolnay

This comment has been minimized.

Copy link
Member Author

dtolnay commented May 29, 2017

Another case to consider here:

impl From<InternalFrom<Error>> for Error

The InternalFrom type is private but this is an implementation of a public trait so it is part of the public API. Maybe this is fine but then rustdoc should not show this impl.

@dtolnay

This comment has been minimized.

Copy link
Member Author

dtolnay commented May 30, 2017

I would like to propose that if a public trait has a private super trait, then:

  • The private supertrait must be named Sealed.
  • The private supertrait must have no methods.
  • The private supertrait must have no supertraits of its own.

The name Sealed means users can get used to this pattern and won't be frustrated by not being able to see something like HeaderClone in the documentation.

The other two points do not affect the API so I guess they don't belong in API guidelines, but they make this confusing pattern easier to see and understand when reading code.

@dtolnay

This comment has been minimized.

Copy link
Member Author

dtolnay commented May 30, 2017

Public trait implementations that are not intended to be available to users, like impl From<InternalFrom<Error>> for Error, should have #[doc(hidden)].

@dtolnay

This comment has been minimized.

Copy link
Member Author

dtolnay commented Oct 29, 2017

This is sufficiently covered by C-SEALED and C-HIDDEN.

@dtolnay dtolnay closed this Oct 29, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.