# Is there a metaprogramming package for struct creation?

**URL:** <https://discourse.julialang.org/t/is-there-a-metaprogramming-package-for-struct-creation/69055>\
**Category:** New to Julia\
**Tags:** metaprogramming, parametric-types, constructors\
**Created:** [October 1, 2021, 4:28pm UTC](https://discourse.julialang.org/t/is-there-a-metaprogramming-package-for-struct-creation/69055 "2021-10-01T16:28:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [October 1, 2021, 4:28pm UTC](https://discourse.julialang.org/t/is-there-a-metaprogramming-package-for-struct-creation/69055/1 "2021-10-01T16:28:14Z")

</div>

@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](https://discourse.julialang.org/t/basic-struct-usage-questions/68932)  
[Struct: access only one element from it - New to Julia - JuliaLang](https://discourse.julialang.org/t/struct-access-only-one-element-from-it/68977)

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?

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [October 1, 2021, 4:55pm UTC](https://discourse.julialang.org/t/is-there-a-metaprogramming-package-for-struct-creation/69055/2 "2021-10-01T16:55:43Z")

</div>

How about [https://github.com/jonniedie/ConcreteStructs.jl](https://github.com/jonniedie/ConcreteStructs.jl) ?

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [October 1, 2021, 5:02pm UTC](https://discourse.julialang.org/t/is-there-a-metaprogramming-package-for-struct-creation/69055/3 "2021-10-01T17:02:27Z")

</div>

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.

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

```

will expand to something like

```julia
struct Foo{T <: Number, U <: AbstractString}
    a::T
    b::U
end

```
