问题描述
是否可以向上转换 Rc<dyn Foo>
?如果没有,为什么不呢?
use std::rc::Rc;
trait Bar {}
trait Foo: Bar {}
fn upcast(this: Rc<dyn Foo>) -> Rc<dyn Bar> {
this
}
结果
error[E0308]: mismatched types
--> src/core/mod.rs:20:5
|
19 | fn upcast(this: Rc<dyn Foo>) -> Rc<dyn Bar> {
| ----------- expected `Rc<(dyn Bar + 'static)>` because of return type
20 | this
| ^^^^ expected trait `Bar`,found trait `Foo`
|
= note: expected struct `Rc<(dyn Bar + 'static)>`
found struct `Rc<(dyn Foo + 'static)>`
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)