mojo
mojo copied to clipboard
[stdlib] Use UInt8 as the storage type for `StringRef`
Note to the maintainers:
Something we can see here is that it's a pain to have other structs/methods/functions access the attributes or our containers directly. Here since I changed the .data
attribute, a lot of code broke, but it should not have been the case since methods _as_ptr()
and _as_uint8_ptr()
were provided.
I would advise to make the attributes of our struct private and to provide public getters and setters to allow other functions to use the pointers and such in a future-proof way.
Long story short, for StringRef
, that would mean:
-
var data: DTypePointer[DType.uint8]
->var _data: DTypePointer[DType.uint8]
-
fn _as_uint8_ptr(self)
->fn get_unsafe_ptr(self)
I agree with adding underscores to attributes that should not be accessed directly
✅🟣 This contribution has been merged 🟣✅
Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the nightly branch during the next Mojo nightly release, typically within the next 24-48 hours.
We use Copybara to merge external contributions, click here to learn more.