core: Add to_bytes method to StrSlice trait
auto merge of #5391 : brson/rust/to-bytes, r=graydon

r?

I want to use this function as a method. There's probably a better way to design this but the existing `ToBytes` trait is not what I am looking for (it has a parameter to indicate the byte order).