Hey all. So what I’d like to do is to have a bunch of values, u8s or whatever, that are “2D”, so you index them with
(x,y) indexes. Easy. But what I’d also like to do is to have “slice-like” views into the whole grid. This seems next to impossible to do ergonomically, because the Traits from
std::ops don’t really seem to allow for it.
Now we all know that Vec derefs to a slice, and String derefs to a str, but the way that it happens seems to border on magic. Slice seems to be a builtin fat pointer that the compiler just knows how to handle, and &str also seems to be a semi-magical type and I’m not sure where the data “inside” the str value is even living when you return a &str.
To slice a 2d thing properly, you’d need more than (ptr/len), you need (ptr/height/width/pitch); I’m not sure how to have a “base” type that derefs into a (ptr/height/width/pitch) blob, because the sub-slice struct doesn’t live long enough. I went around on this whole thing on IRC last night, and it kept feeling like we almost had it until we didn’t have it. I’m not sure if we weren’t expert enough or if you just can’t do this in rust using the signatures that the
std::ops traits force you to use.
Playground link of what I had in mind so far and about where I got stuck: