should erased types be considered part of a crate's public API? #162
BurntSushi
started this conversation in
General
Replies: 2 comments
-
I would be on board with recommending that the underlying type of a trait object or impl Trait should not be considered public API unless documented as such. How would you propose wording this guideline, given that it mainly deals with how users interact with an API rather than how the API is designed? Mentioning @seanmonstar who brought up the same question in #96. |
Beta Was this translation helpful? Give feedback.
0 replies
-
@dtolnay Oh! I didn't realize #96 existed. I'd be OK closing this and merging into #96. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For example, let's say someone is using the
failure
crate and builds errors like this in a crate wherecsv
is intended to be a private dependency:Given the above, there is no direct exposure of the
csv::Error
type. However, it is possible for callers to iterate over the causes of the returned error and downcast to capture thecsv::Error
. If my library bumps its internal major version of thecsv
crate, then it possible that uses of my crate that downcast tocsv::Error
will stop working, since vN'scsv::Error
type is distinct from v(N+1)'scsv::Error
type.There are some interesting angles on this problem:
This was discussed a little bit here: https://users.rust-lang.org/t/when-returning-a-trait-object-is-the-underlying-concrete-type-a-part-of-your-public-api --- My summary of that thread is probably that erased types shouldn't be considered a part of a crate's public API by default. With that said, I can imagine that there may (as yet) exist crates where downcasting is a central focus of its API, and where changes on that front may be considered breaking.
As a counterpoint to the URLO thread, with respect to
failure
, I can see this coming up in the following interesting way:failure
gains dominance as the way to handle errors in Rust.io::Error
, and I can imagine other use cases that extend to other error types.We should find a way to settle on a guideline here. For example, one possible guideline: "In general, assume that erased types are not a public part of a crate's API, but a crate may elect to document otherwise." Or perhaps a different but more specific guideline, "In general, a change in the behavior of a
downcast
is not considered a backwards incompatible change for the purposes of semver, but crates may elect to document otherwise." The former feels slightly more slimy than the latter to me, although perhaps it is a distinction without a difference.Beta Was this translation helpful? Give feedback.
All reactions