I find pretty weird that
use std::sync::Arc;
trait Fruit {}
struct Pear {}
impl Fruit for Pear {}
fn main() {
let pear = Arc::new(Pear {});
let cloned = Arc::clone(&pear);
let cloned_casted: Arc<dyn Fruit> = cloned;
}
compiles, but
use std::sync::Arc;
trait Fruit {}
struct Pear {}
impl Fruit for Pear {}
fn main() {
let pear = Arc::new(Pear {});
let cloned_casted: Arc<dyn Fruit> = Arc::clone(&pear);
}
errors out with
error[E0308]: mismatched types
--> main.rs:9:52
|
9 | let cloned_casted: Arc<dyn Fruit> = Arc::clone(&pear);
| ^^^^^ expected trait object `dyn Fruit`, found struct `Pear`
|
= note: expected reference `&Arc<dyn Fruit>`
found reference `&Arc<Pear>`
Why is so, and is there a shorter variant to clone Arc<dyn Fruit>
from Arc<Pear>
?