From 16cf404f9853e716a216be32d05f5215ff821c00 Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Fri, 21 Sep 2018 01:24:52 +0100 Subject: [PATCH] Added section to Unstable Book. --- .../impl-trait-in-bindings.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/doc/unstable-book/src/language-features/impl-trait-in-bindings.md diff --git a/src/doc/unstable-book/src/language-features/impl-trait-in-bindings.md b/src/doc/unstable-book/src/language-features/impl-trait-in-bindings.md new file mode 100644 index 0000000000000..896465cf64978 --- /dev/null +++ b/src/doc/unstable-book/src/language-features/impl-trait-in-bindings.md @@ -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.