Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That’s true, converting in either direction will typically allocate. Which it must, semantically.

One can use unsafe for a zero-copy conversion, but now you are breaking the semantics: a string becomes mutable, because its underlying bytes are mutable.

Or! One can often handle strings and bytes interchangeably with generics: https://github.com/clipperhouse/stringish



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: