Closed johanfforsberg closed 2 years ago
If allocation is needed you should instead use nextAlloc.
The error is actually really misleading if you don't know the internals, I'll have to work on that.
The explanation is that we call readStruct
and readField
in both cases (using next
or nextAlloc
) and because their options
argument is anytype
we can provide an anonymous struct with an allocator or not. See the code.
To make the error clear next
should just do its own verification that the type doesn't require allocation.
Hope that helps.
Oh that was quick :)
So, the actual error is that I need allocation but am trying to use the non allocating version. I should have read the code more carefully, I am still a little confused over what needs allocation in this case. Anyway, I got it to work with iterAlloc()
now, thanks!
(The readme needs a small update though, the example uses &area.allocator
which should be arena.allocator()
in zig 0.10.)
So, the actual error is that I need allocation but am trying to use the non allocating version. I should have read the code more carefully, I am still a little confused over what needs allocation in this case. Anyway, I got it to work with iterAlloc() now, thanks!
I'll try to explain.
Basically any pointer types (single element, slice) requires an allocator because they aren't copyable. If you copy a slice for example, you're not copying its memory, only the pointer and length. Primitive types and arrays are copyable and thus don't require an allocator.
It probably would have been possible to design the iterator in such a way that it uses a single allocator for calls to next
but I think taking an allocator per iteration is more flexible (for example you can easily use an arena per row and then you could give ownership of this "row data" to some other code).
So, the actual error is that I need allocation but am trying to use the non allocating version. I should have read the code more carefully, I am still a little confused over what needs allocation in this case. Anyway, I got it to work with iterAlloc() now, thanks!
Thanks, I'll fix it.
Hi!
This library looks very neat! However I ran into a problem.
I have created a statement and want to iterate over the results, e.g:
This raises a compile error:
However the
QueryOptions
taken bynext()
does not have such a field.I worked around it by adding an
allocator
field toQueryOptions
but it's unclear to me if it's really necessary or if the check is in error.I am using your master branch, and zig
0.10.0-dev.2431+0e6285c8f
.