Fixes for errors and deprecation warnings with recent Rust

Github doesn't appear to be showing all of my changes to src/lib.rs for some reason. If you look at my commit history you can see the full change. I figure this might not apply cleanly but the changes are small enough to be applied by hand if the pull request is no good.