Is there ability to create Rc<T> and Rc<Trait>


#1
trait Trait {}

struct Struct;

impl Trait for Struct {}

Can I create Rc<Box<Trait>> and Rc<Box<Struct>> with one value

let obj = Box::new(Struct);
let struct_rc = Rc::new(obj);
let trait_rc = Rc::new(obj);

Is my question understandable?


#2

Are you looking for this?

use std::rc::Rc;

trait Trait {}

struct Struct;

impl Trait for Struct {}

fn main() {
    let struct_rc: Rc<Struct> = Rc::new(Struct);
    let trait_rc: Rc<Trait> = struct_rc.clone() as Rc<Trait>;
}

#3

Yes. Thanks.