Yeah, I gotcha. I’m going to write out a few things that you are probably aware of but through the context of Zig.
Conceptually, based on the function you’ve provided, this isn’t even really doable by design.
pub something(data: []u8) void {
data[0] = 1;
}
Say for example I could use some kind of “in situ” syntax:
something(mutable &[1]u8{ 0 });
Well… now what? How do I get my array back? That function returns void
so I just kinda threw it down a hole. This may be because the example you’re posting is a simplified one but in this case, it’s really not understandable. Not trying to nitpick ya, but it’s hard to know what the goal is here.
Fundamentally, remember what a slice is - it’s a length and a pointer. Slices don’t contain stuff, they point to stuff and tell you how much stuff is there. So if I create a slice to something, it needs to be in a defined location.
Creating literals like in your example actually does put it somewhere! It’s just in data segment of your binary. If you want to see this in action, please read this thread: Diving deep into anonymous struct literals - #3 by bnl1
So as it stands, as far as slices are concerned, I don’t think this really makes sense. Hopefully you get what I’m driving at here.