#Can you concat a string literal and a [_][]const u8?
1 messages · Page 1 of 1 (latest)
string literals can implicitly coerce to []const u8, yes
but thats not how to concatenate slices
since you don't know the length of args you'll have to use std.mem.concat
and allocate, right
std.mem.concat allocates,yes
meh I might as well pass "query" in args
or append to a bounded array
which is becoming my fav collection
it would be awesome to have a bounded array that allocates if it exceeds the comptime size
like SmallVec in rust
Sounds like what you want is an ArrayList backed by a StackFallbackAllocator
StackFallbackAllocator allocates into a fixed buffer, and if you exceed the buffer size, then starts using a fallback allocator
You could use one something like this:
var sfb = std.heap.stackFallback(1024, allocator); // reserves a 1024 byte stack buffer
const sfba = sfb.get();
var bytes = std.ArrayList(u8).init(sfba);
defer bytes.deinit();
// do stuff with bytes