Avatar ·

How to get an owned value from `Box<T>` in Rust without copying?

Hi everyone! I started learning Rust and encountered a problem when working with smart pointers. I have a struct that doesn't implement the `Copy` trait (for example, it contains `Vec` or `String`). I put it in `Box` to pass it to the heap, but then I need to extract the original value back to continue working with it without borrowing. Here's an example: ```rust struct Data { numbers: Vec, } fn main() { let boxed = Box::new(Data { numbers: vec![1, 2, 3] }); // How to get Data back so that numbers is moved? // I want something like: let data = boxed.into_inner(); // But there's no such method! } ``` I tried using `*boxed` for dereferencing, but it gives a reference, not ownership. I tried `let data = *boxed;` — the compiler