Added page to Unstable Book.

This commit is contained in:
Alexander Regueiro 2019-10-31 03:53:51 +00:00 committed by Charles Lew
parent a1cff1cd49
commit b867376cb3

View file

@ -0,0 +1,26 @@
# `trait_upcasting`
The tracking issue for this feature is: [#31436]
[#65991]: https://github.com/rust-lang/rust/issues/65991
------------------------
The `trait_upcasting` feature adds support for trait upcasting. This allows a
trait object of type `dyn Foo` to be cast to a trait object of type `dyn Bar`
so long as `Foo: Bar`.
```rust,edition2018
#![feature(trait_upcasting)]
trait Foo {}
trait Bar: Foo {}
impl Foo for i32 {}
impl<T: Foo + ?Sized> Bar for T {}
let foo: &dyn Foo = &123;
let bar: &dyn Bar = foo;
```