Is there a way to create a custom data structure that can be used with the for loop?
I figured that such data structure needs to be “indexable” given the error I get:
type 'MyCustomType' is not indexable and not a range
So question is, can I also define a custom data type that is “indexable”
By the way I am aware of ability to create a custom iterator that can be used with a while loop but this question is more about exploring and understanding Zig better: what can and cannot be done.
As far as I know, it is not possible to implement some magic method to make your data structure work with a for loop.
According to the docs here, a for loop iterates over slices and arrays, no mention of implementing it for other types are made.
But I’d be glad to be proven wrong.