Replace ~ with Box

This upgrades the code to the latest Rust version.