File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
src/doc/unstable-book/src/language-features Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments