mojo icon indicating copy to clipboard operation
mojo copied to clipboard

Introduce stdlib types and methods for dealing with raw bytes

Open lsh opened this issue 1 year ago • 2 comments

Review Mojo's priorities

What is your request?

At minimum it would be useful to have a data structure like

struct Bytes:
  var data: DynamicVector[UInt8]

Naming is a bikeshed issue.

What is your motivation for this change?

Since the String type will have a small string optimization, there needs to be a way to convert a string to the expected ByteArray representation. Therefore we'd need .to_bytes on String.

Any other details?

It's worth considering how this type fits in with the generic std list type. It should also probably fit in with the Base64 module.

lsh avatar Jul 23 '23 22:07 lsh

.to_bytes is not pythonic. Do you mean str.encode(encoding='utf-8', errors='strict')?

drunkwcodes avatar Jul 24 '23 08:07 drunkwcodes

I just noticed this issue, linking https://github.com/modularml/mojo/pull/2096 for better visibility

gabrieldemarmiesse avatar Apr 24 '24 15:04 gabrieldemarmiesse