Use BytesView instead of Bytes (+add Utf8 hint type)#50
Conversation
Not good :( At least if I get it right. Most of the strings are static strings. Also, returning (for instance, from |
|
To be clear, I meant "no way to get string literals on custom structs" You do get the implicit conversion on type aliases, like we have in this PR. However in this snippet: firefly-moon/example/random/main.mbt Lines 12 to 17 in 700fc8a ^I had to add the |
|
Alright, I trust you. You're the MoonBit expert here :) |
Changes to use
BytesViewmore, as it seems to be a better convention for function parameters asBytesimplicitly converts to aBytesView.I also added "hint alias types" for
Utf8andUtf8Viewto try better hint where UTF-8 input is required. Sadly the LSP currently only view the aliased typeBytes/BytesView, and doesn't even allow "jump to definition" for type aliases. And there's currently no way to get string literals to implicitly convert to custom types. Bummer. But maybe that will be fixed in the future?One issue here is that using views will force import the stdlib's
abortimplementation, which does some string andSourceLocshenaginans which brings in ~5kB of code: https://github.com/moonbitlang/core/blob/05aaf6a8164093e22247519255cccdcabd7870c6/builtin/intrinsics.mbt#L64-L78No additional code is imported if the app already uses any other standard library function that calls
@builtin.abort, which for more complicated projects is somewhat unavoidable.