Is there a metaprogramming package for struct creation?

@flalom and I recently fell into the same beginner trap of setting the fields of a struct to abstract types:
Basic struct usage questions - New to Julia - JuliaLang
Struct: access only one element from it - New to Julia - JuliaLang

The solution is to use parametric types with constructors which quickly gets complicated. Are there any metaprogramming packages that can help simplify good struct creation?

1 Like

How about GitHub - jonniedie/ConcreteStructs.jl: 🏩🏠🌆🏨🌇🏦 ?

2 Likes

Something missing from the documentation of the package is that you can constrain fields to be within some abstract type using @concrete as well. E.g.

@concrete struct Foo
    a<:Number
    b<:AbstractString
end

will expand to something like

struct Foo{T <: Number, U <: AbstractString}
    a::T
    b::U
end
1 Like