1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
use std::process::Child; pub struct KillOnDrop(Child); impl Drop for KillOnDrop { fn drop(&mut self) { self.0.kill().unwrap(); } } pub trait ChildExt { fn kill_on_drop(self) -> KillOnDrop; } impl ChildExt for Child { fn kill_on_drop(self) -> KillOnDrop { KillOnDrop(self) } }