ok, thanks. But would like to turn a variable like trait_object_ref into a variable like trait_object, not the other way around, for example if I get it as function argument.
Box<dyn Trait> is usually short for Box<dyn Trait + 'static>, and it's not uncommon to want or need a Box<dyn Trait + 'static> instead of a lifetime-limited one like Box<dyn Trait + 'a>. For those, the clone_boxed pattern @semicoleon provided can be adjusted:
Note that the implementation did not change in the example, but now we have a Box<dyn Trait + 'static>. On the other hand, this won't work for non-'static types.
Which pattern is better depends on your use case. If you can support Box<dyn Trait + 'a>, it might be the case that you can support &'a dyn Trait (aka &'a (dyn Trait + 'a)) instead.