Guidance around impl Trait #60
Replies: 3 comments 2 replies
-
From servo/rust-url#305 (comment):
|
Beta Was this translation helpful? Give feedback.
-
This discussion is a bit older, but maybe it can be revived?
I know of the following advantages when using
However, the additional freedom for authors of the API comes with some severe drawbacks for consumers. I think they can be summarized as "the user can't name the type". This includes at least the following two concrete problems:
Thus, it seems to me that libraries should generally avoid using |
Beta Was this translation helpful? Give feedback.
-
So, should I open a PR to include such a guideline? Maybe under Flexibility, |
Beta Was this translation helpful? Give feedback.
-
This can wait until closer to stabilization rust-lang/rust#34511.
When should you consider using
impl Trait
? What are some reasons you should consider not usingimpl Trait
?In the
url
evaluation we discussed howResult<T, impl Error>
is bad because the caller cannot handle it with?
. This seems like a general concern that extends to lots of cases other thanError
.Beta Was this translation helpful? Give feedback.
All reactions