sora
MModular
•Created by Ryan on 11/1/2024 in #questions
How Unsafe/Safe is this code?
Don't you need some sort of index to size mapping for this to work?
5 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Could you share your GitHub handle so I can give you credit in the description?
52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
I actually already made a PR for it: https://github.com/modularml/mojo/pull/3698
52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Except
StringRef
is an unsafe type mainly meant for C++ interop which you probably should avoid using, people are trying to replace them with string slice in the stdlib52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
FYI, Mojo stdlib is apache 2 with LLVM exceptions, so if you are allowed to contribute to most libs for Rust, you should be fine.
52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Not at all, it's just people haven't implemented it yet. You could add that to the stdlib if you are interested.
52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Ah, Mojo does "prevent" you from returning the
Span
unless you manually rebind the lifetime parameter52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
What do you mean by local lt?
52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
You can in fact avoid alloc, using
InlineArray
would be equivalent.
52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
This is more the idiom
52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
I'm not sure since inline array is allocated on the stack
52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Yea,
UnsafePointer[Byte].alloc
, or String._buffer_type(capacity=...)
52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Implicit conversion itself is not a bug. Accidentally making
String
constructable from UnsafePointer[Byte]
is.52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
buf
got freed too earily52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Nothing to do with the constructor per se. Mojo finds the overload where each argument undergoes at most one implicit conversion.
52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Could you include the whole program?
52 replies
MModular
•Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
I think you are correct and that's horrible, we should fix it
52 replies