diff options
| author | Alexander Regueiro <alexreg@me.com> | 2019-10-31 03:53:51 +0000 |
|---|---|---|
| committer | Charles Lew <crlf0710@gmail.com> | 2021-08-03 01:09:37 +0800 |
| commit | b867376cb3fb601c5d3ca8cce75445b5dec2a806 (patch) | |
| tree | 3635a1f307eb25650fd3e558b111d9919c76daa9 | |
| parent | a1cff1cd4990a4ee8c5df8d7c71c05a0bcd60dec (diff) | |
| download | rust-b867376cb3fb601c5d3ca8cce75445b5dec2a806.tar.gz rust-b867376cb3fb601c5d3ca8cce75445b5dec2a806.zip | |
Added page to Unstable Book.
| -rw-r--r-- | src/doc/unstable-book/src/language-features/trait-upcasting.md | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/language-features/trait-upcasting.md b/src/doc/unstable-book/src/language-features/trait-upcasting.md new file mode 100644 index 00000000000..b7aafe58c31 --- /dev/null +++ b/src/doc/unstable-book/src/language-features/trait-upcasting.md @@ -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; +``` |
