Is there no Box<T> -> T function?

I'm looking at

I can't seem to find a Box<T> -> T function.

Intuitively, this function should exist since it's just "moving object from Heap to Stack".

Does this function exist? If not, why?



assuming the contents are Sized, a dereference can be used to move something out of the box

so this works

fn main() {
    let boxed = Box::new("test".to_owned());
    let unboxed = *boxed;

but not

struct A {}
trait T {}
impl T for A {}

fn main() {
    let boxed: Box<dyn T> = Box::new(A {});
    let unboxed = *boxed;
1 Like

deref worked. Thanks!