-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexander Regueiro
committed
Sep 25, 2018
1 parent
3b14450
commit 16cf404
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/doc/unstable-book/src/language-features/impl-trait-in-bindings.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# `impl_trait_in_bindings` | ||
|
||
The tracking issue for this feature is: [#34511] | ||
|
||
[#34511]: https://github.com/rust-lang/rust/issues/34511 | ||
|
||
------------------------ | ||
|
||
The `impl_trait_in_bindings` feature gate lets you use `impl Trait` syntax in | ||
`let`, `static`, and `const` bindings. | ||
|
||
A simple example is: | ||
|
||
```rust | ||
#![feature(impl_trait_in_bindings)] | ||
|
||
use std::fmt::Debug; | ||
|
||
fn main() { | ||
let a: impl Debug + Clone = 42; | ||
let b = a.clone(); | ||
println!("{:?}", b); // prints `42` | ||
} | ||
``` | ||
|
||
Note however that because the types of `a` and `b` are opaque in the above | ||
example, calling inherent methods or methods outside of the specified traits | ||
(e.g., `a.abs()` or `b.abs()`) is not allowed, and yields an error. |