<FromGitter>
<mjfiano:matrix.org> Might be a dumb question, but specs gives an internal error when i switch my code to use struct instead of class, saying `same?` method is undefined, probably from using the spectation `should be`.
<FromGitter>
<Blacksmoke16> yes
<FromGitter>
<Blacksmoke16> makes sense
<FromGitter>
<mjfiano:matrix.org> Yeah thought so, since they are pbv
<FromGitter>
<mjfiano:matrix.org> ok
<FromGitter>
<Blacksmoke16> you could use `should be` if your struct implemented that method
<FromGitter>
<Blacksmoke16> but at that point its basically the same as `should eq`
<FromGitter>
<mjfiano:matrix.org> Right
<FromGitter>
<Blacksmoke16> 👍
<FromGitter>
<mjfiano:matrix.org> I'm just experimenting by removing all those "into" methods and making the types structs
<FromGitter>
<mjfiano:matrix.org> It would surely be a lot less code to maintain and probably less room for user error
<FromGitter>
<Blacksmoke16> indeed
ua_ has quit [Ping timeout: 272 seconds]
ua_ has joined #crystal-lang
ur5us has joined #crystal-lang
sagax has joined #crystal-lang
ur5us has quit [Ping timeout: 272 seconds]
echoSMILE has left #crystal-lang [#crystal-lang]
f1refly has quit [Read error: Connection reset by peer]
<FromGitter>
<mjfiano:matrix.org> heh this library is only 1500 lines, but test boilerplate is about 5000
deavmi has quit [Ping timeout: 240 seconds]
deavmi has joined #crystal-lang
<FromGitter>
<Blacksmoke16> :P sounds about right
<FromGitter>
<mattrberry> `out` just creates an uninitialized variable for whatever type is being pointed to, right?
<FromGitter>
<mattrberry> So `out` for an argument that's a `Pointer(Char)` effectively just creates an `uninitialized Char` then passes its pointer as an argument, right?
<FromGitter>
<mattrberry> If I want to allocate space for a string, I'd need to allocate that myself using something like Pointer.malloc or just `buffer = " " * 512` then pass the pointer
<FromGitter>
<mattrberry> When I just use `out` in the case where I *know* it's filling many characters it's still working, but I'm guessing that it's just writing to memory that's still addressable so it's getting lucky and not segfaulting. I just wanted to make sure the Crystal compiler wasn't doing anything tricky with the `out` syntax that I wasn't expecting
<FromGitter>
<mattrberry> So I'll stick to just allocating space myself first
<FromGitter>
<Blacksmoke16> could you do something with a slice?
<FromGitter>
<Blacksmoke16> like `Bytes.new size`, then pass a pointer to that buffer to fill it?
<FromGitter>
<Blacksmoke16> then you'd be able to do `String.new bytes`
<FromGitter>
<mattrberry> The benefit of just setting `buffer = " " * n` is that to_unsafe already gives me a Pointer(UInt8), so I can just pass it directly to the c binding, and in Crystal it's already a string so I don't need to do anything funky with it
<FromGitter>
<Blacksmoke16> thats fair, the other option would be to `maloc` a pointer and use the `String.new ptr, size` constructor
<FromGitter>
<Blacksmoke16> `malloc`*
<FromGitter>
<mattrberry> Yeah that was my other thought too. Any thought if there's any perf concern with `" " * n`? It's not in a hotpath so I'm not overly concerned, but worth considering at least