Replace some unsafe code with a safe stdlib wrapper.

My rust is too old to actually build this to test; so it should be checked by hand. (Sorry!)

In theory these have minimal extra cost over the manual memcpys.