I want to create a thread inside of the new method and stop it after the struct is destroyed:
new
use std::thread; struct Foo { handle: thread:
If you don't mind unsafe code, then here's something you could do (please look at Matthieus answer why this can be a bad idea).
struct Foo { handle: ManuallyDrop>, } impl Drop for Foo { fn drop(&mut self) { unsafe { let _ = ManuallyDrop::take(&mut self.handle).join(); } } }