Skip to content

Update C-NEWTYPE-HIDE now impl Trait is shipped #178

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

Merged
merged 4 commits into from
Sep 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/future-proofing.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,19 @@ less to the client. The client does not know _how_ the result iterator is
constructed or represented, which means the representation can change in the
future without breaking client code.

In the future the same thing can be accomplished more concisely with the [`impl
Trait`] feature but this is currently unstable.
Rust 1.26 also introduces the [`impl Trait`][] feature, which is more concise
than the newtype pattern but with some additional trade offs, namely with `impl
Trait` you are limited in what you can express. For example, returning an
iterator that impls `Debug` or `Clone` or some combination of the other iterator
extension traits can be problematic. In summary `impl Trait` as a return type
is probably great for internal APIs and may even be appropriate for public APIs,
but probably not in all cases. See the ["`impl Trait` for returning complex
types with ease"][impl-trait-2] section of the Edition Guide for more details.

[`impl Trait`]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
[impl-trait-2]: https://rust-lang-nursery.github.io/edition-guide/rust-2018/trait-system/impl-trait-for-returning-complex-types-with-ease.html

```rust
#![feature(conservative_impl_trait)]

pub fn my_transform<I: Iterator>(input: I) -> impl Iterator<Item = (usize, I::Item)> {
input.skip(3).enumerate()
}
Expand Down