Skip to content

Commit b4c1aef

Browse files
committed
Add universal_impl_trait unstable-book entry
1 parent 04ad8fd commit b4c1aef

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# `universal_impl_trait`
2+
3+
The tracking issue for this feature is: [#34511].
4+
5+
[#34511]: https://github.com/rust-lang/rust/issues/34511
6+
7+
--------------------
8+
9+
The `universal_impl_trait` feature extends the [`conservative_impl_trait`]
10+
feature allowing the `impl Trait` syntax in arguments (universal
11+
quantification).
12+
13+
[`conservative_impl_trait`]: ./language-features/conservative-impl-trait.html
14+
15+
## Examples
16+
17+
```rust
18+
#![feature(universal_impl_trait)]
19+
use std::ops::Not;
20+
21+
fn any_zero(values: impl IntoIterator<Item = i32>) -> bool {
22+
for val in values { if val == 0 { return true; } }
23+
false
24+
}
25+
26+
fn main() {
27+
let test1 = -5..;
28+
let test2 = vec![1, 8, 42, -87, 60];
29+
assert!(any_zero(test1));
30+
assert!(bool::not(any_zero(test2)));
31+
}
32+
```

0 commit comments

Comments
 (0)