Skip to content

Commit 16cf404

Browse files
author
Alexander Regueiro
committed
Added section to Unstable Book.
1 parent 3b14450 commit 16cf404

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# `impl_trait_in_bindings`
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 `impl_trait_in_bindings` feature gate lets you use `impl Trait` syntax in
10+
`let`, `static`, and `const` bindings.
11+
12+
A simple example is:
13+
14+
```rust
15+
#![feature(impl_trait_in_bindings)]
16+
17+
use std::fmt::Debug;
18+
19+
fn main() {
20+
let a: impl Debug + Clone = 42;
21+
let b = a.clone();
22+
println!("{:?}", b); // prints `42`
23+
}
24+
```
25+
26+
Note however that because the types of `a` and `b` are opaque in the above
27+
example, calling inherent methods or methods outside of the specified traits
28+
(e.g., `a.abs()` or `b.abs()`) is not allowed, and yields an error.

0 commit comments

Comments
 (0)