about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Regueiro <alexreg@me.com>2018-10-22 02:55:01 +0100
committerAlexander Regueiro <alexreg@me.com>2018-11-03 04:09:34 +0000
commit1cda3c3b49183b60dc90ec1b19e494ff118c976c (patch)
treee4a917cb56add9013f96139b53f6ea8d48aff0b1
parent4751953d5f2cd88243e3fac9a84271ed7a2636b4 (diff)
downloadrust-1cda3c3b49183b60dc90ec1b19e494ff118c976c.tar.gz
rust-1cda3c3b49183b60dc90ec1b19e494ff118c976c.zip
Added section to Unstable Book.
-rw-r--r--src/doc/unstable-book/src/language-features/trait-alias.md34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/language-features/trait-alias.md b/src/doc/unstable-book/src/language-features/trait-alias.md
new file mode 100644
index 00000000000..4f2db040160
--- /dev/null
+++ b/src/doc/unstable-book/src/language-features/trait-alias.md
@@ -0,0 +1,34 @@
+# `trait_alias`
+
+The tracking issue for this feature is: [#41517]
+
+[#41417]: https://github.com/rust-lang/rust/issues/41517
+
+------------------------
+
+The `trait_alias` feature adds support for trait aliases. These allow aliases
+to be created for one or more traits (currently just a single regular trait plus
+any number of auto-traits), and used wherever traits would normally be used as
+either bounds or trait objects.
+
+```rust
+#![feature(trait_alias)]
+
+trait Foo = std::fmt::Debug + Send;
+trait Bar = Foo + Sync;
+
+// Use trait alias as bound on type parameter.
+fn foo<T: Foo>(v: &T) {
+    println!("{:?}", v);
+}
+
+pub fn main() {
+    foo(&1);
+
+    // Use trait alias for trait objects.
+    let a: &Bar = &123;
+    println!("{:?}", a);
+    let b = Box::new(456) as Box<dyn Foo>;
+    println!("{:?}", b);
+}
+```