Static structs with constant field

I’m not exactly sure I understand what you’re asking, but it looks like you’re mixing the definition of a struct with the construction of an instance of that struct.

I think what you want to do is this:

struct MyStruct
    a::Int
    b::String
end

const A = MyStruct(1, "value")

at the repl we see

julia> println(A.b)
value

Another thing you could do is use a NamedTuple, they’re a big like ‘anonymous structs’, e.g.

julia> const A = (;a=1, b="value")
(a = 1, b = "value")

julia> println(A.b)
value
7 Likes