Skip to content

Commit 1cda3c3

Browse files
author
Alexander Regueiro
committed
Added section to Unstable Book.
1 parent 4751953 commit 1cda3c3

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# `trait_alias`
2+
3+
The tracking issue for this feature is: [#41517]
4+
5+
[#41417]: https://github.com/rust-lang/rust/issues/41517
6+
7+
------------------------
8+
9+
The `trait_alias` feature adds support for trait aliases. These allow aliases
10+
to be created for one or more traits (currently just a single regular trait plus
11+
any number of auto-traits), and used wherever traits would normally be used as
12+
either bounds or trait objects.
13+
14+
```rust
15+
#![feature(trait_alias)]
16+
17+
trait Foo = std::fmt::Debug + Send;
18+
trait Bar = Foo + Sync;
19+
20+
// Use trait alias as bound on type parameter.
21+
fn foo<T: Foo>(v: &T) {
22+
println!("{:?}", v);
23+
}
24+
25+
pub fn main() {
26+
foo(&1);
27+
28+
// Use trait alias for trait objects.
29+
let a: &Bar = &123;
30+
println!("{:?}", a);
31+
let b = Box::new(456) as Box<dyn Foo>;
32+
println!("{:?}", b);
33+
}
34+
```

0 commit comments

Comments
 (0)