kotlinx-io icon indicating copy to clipboard operation
kotlinx-io copied to clipboard

Replace `ByteString(ByteArray)` constructor with `ByteArray.toByteString()`

Open joffrey-bion opened this issue 1 year ago • 0 comments
trafficstars

This current "safe" constructor doesn't feel right. It has the following drawbacks:

  • the constructor syntax implies "wrapping" (as if the array is used as a property), but what actually happens is a copy
  • it's hard to discover: when I want to turn a ByteString into a ByteArray, the completion helps me find the toByteArray() extension. When I look for the inverse operation, I can't find it via completion
  • it's not symmetrical with the ByteString.toByteArray() counterpart
  • it's not easily composable: nullableByteString?.toByteArray() is nice, while nullableByteArray?.let { ByteString(it) } is not nice

Adding a ByteArray.toByteString() extension would solve all of these.

joffrey-bion avatar Feb 13 '24 15:02 joffrey-bion