Is there any way to cast a trait object (dyn A
) to another type (dyn B
) safely?
trait A {}
trait B: A {}
impl <T: A> B for T {}
fn cast(x: &dyn A) -> &dyn B {
x
}
error[E0308]: mismatched types
--> src/lib.rs:6:3
|
6 | x
| ^ expected trait `B`, found trait `A`
|
= note: expected type `&dyn B`
found type `&dyn A`