T being the element type, and the pointer being const or not depending on mutability.
It’s just pointing to the first element and has a length.
ofc you can make a slice that starts in the middle or end of the array and with a shorter length than the remaining total length.
A caveat to be aware of: when you slice with from 0 with a comptime known length you will get a pointer to an array instead of a slice, you won’t notice most cases since pointers to an array can coerce to a slice.
Which is the case with your example, I point this out because you cannot== slices, but you can == pointers, if slice was actually a slice then you would need to compare to the ptr field.
Yes, you’ve got it. So, agreed: the documentation DOES state the caveat about comptime-known-length (that you’ll get a pointer to an array instead of a slice), and I guess that’s all there really is to it, here. But that led me to believe I wouldn’t be able to slice.ptr (since you can’t array.ptr, and that should be a pointer to an array, technically, since the length was comptime-known), but this code disproves that. Before that, though, I wasn’t sure if &array would == slice, though I hoped/expected that that’s exactly what I’d get in this case. Perhaps detail like this is unnecessary or duplicate, but I was unsure until I looked at the code and then ran this test to confirm.
I think it’s now incomplete because there are some more conversions possible (like from array to slice with &). But maybe this helps a bit with understanding the differences.
You can kind of read the article here in the dump. Search for “In the Zig language, when working with a sequence of” if the link isn’t working.
On that graph, all the & conversions can be found by flipping the direction of the .* conversions. You can also invert the .ptr conversions with subslicing syntax ([0..] or [0..len]). Thanks for sharing this!
What a great aggregation of useful detail on this; thank you all. I’d love to see that chart in documentation someday, augmented, as mentioned. @Zambyte, thank you for that characterization - very nicely put.