]> git.lizzy.rs Git - rust.git/blob - src/doc/unstable-book/src/language-features/impl-trait-in-bindings.md
Rollup merge of #69403 - LeSeulArtichaut:copy-ioslice, r=sfackler
[rust.git] / src / doc / unstable-book / src / language-features / impl-trait-in-bindings.md
1 # `impl_trait_in_bindings`
2
3 The tracking issue for this feature is: [#63065]
4
5 [#63065]: https://github.com/rust-lang/rust/issues/63065
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.