# "@generated" for structs?

**URL:** <https://discourse.julialang.org/t/generated-for-structs/71803>\
**Category:** General Usage\
**Tags:** struct\
**Created:** [November 19, 2021, 10:40pm UTC](https://discourse.julialang.org/t/generated-for-structs/71803 "2021-11-19T22:40:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wmanning-cra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wmanning-cra/32/30967_2.png) [@wmanning-cra](https://discourse.julialang.org/u/wmanning-cra)\
**Post date:** [November 19, 2021, 10:40pm UTC](https://discourse.julialang.org/t/generated-for-structs/71803/1 "2021-11-19T22:40:46Z")

</div>

I was playing with code that generates a struct + accompanying code, based on a set of information that can be represented with groups of symbols. It occurred to me that I could simplify the syntax around this stuff if I could do something like, for example:

```julia
@generated struct MyStruct{A::Symbol, B::Tuple, C}
        fields = collect(:($(esc(param))::C) for param in B.parameters)
        constructors = begin [do some stuff with A and C] end
        return quote
              $fields
              $constructors
       end
end

```

Is there anything like this in Julia? And if not, is there a good reason, or is it just an idea nobody has gotten to? I don’t really understand the inner workings of @generated functions yet.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [November 20, 2021, 12:21am UTC](https://discourse.julialang.org/t/generated-for-structs/71803/2 "2021-11-20T00:21:05Z")

</div>

I don’t think something like _dynamically_ changing the fields of a struct depending on the type parameter is possible, my guess is it would make the compiler’s job significantly more complex. But if what you want is to more or less splice the fields of one type (your `B` type above) into the fields of another (your `MyStruct`) you might find this useful: [https://github.com/marius311/CompositeStructs.jl](https://github.com/marius311/CompositeStructs.jl)
