Copy the encode_utf8 function from odds. std encode_utf8 requires Rust 1.15 and has a different signature, this one seems to fit us better.