I get this wierd error when i try to implement to_index with a struct

I get this wierd error when i try to implement to_index with a struct:
Base.to_index(s::State) = CartesianIndex(s.x,s.y) errors with
“getindex for Array{Float64,2} with types Tuple{CartesianIndex{2}} is not supported”

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message :slack:) (More Info)

to_index must return a a single Int index or an array of indices; you can’t return a CartesianIndex:

help?> Base.to_index
  to_index(A, i)

  Convert index i to an Int or array of indices to be used as an index into array A.

If you want to spit out more than one index spanning more than one dimension, you unfortunately need to use the more complicated to_indices… and not only do you need to handle your index type, but you also need to play nicely with other indices that might appear alongside yours since we need to end up with a single argument list tuple.

You can probably do something similar to what CartesianIndex itself does — that is,

@inline function Base.to_indices(A, inds, I::Tuple{State, Vararg{Any}})
    s = I[1]
    return to_indices(A, inds, (s.x ,s.y, tail(I)...))