I have
struct S
the_only_field
end
For my struct to hold data, I need it to have a field, and that means I need the field to have a name. But I would like to use it without having to define something like the_only_field(s::S) = s.the_only_field
. So I figured I could make Julia think of S
as a zero-dimensional array and have s[]
give me s.the_only_field
.
I’m trying to follow the documentaiton on the AbstractArray
interface: Interfaces · The Julia Language
Is this the right way to do it?
Base.size(::S) = 0
Base.getindex(::S, i::Integer) = error("S is zero-dimensional. It has no indices. Use [] to get its contents.")
Base.getindex(s::S) = s.the_only_field