Best solution is to use ::std::io::Write, but then you won't be able to use String directly since it requires the emitted / written bytes be valid UTF-8, which is not something the io::Write trait requires or enforces.
So you need to drop the String requirement, and use a Vec<u8> instead. Later on, if you want back a String , you can upgrade the Vec<u8> back to a String using one of the functions dedicated to that purpose (which either fail or perform a lossy conversion when encountering invalid UTF-8 sequences):