# Separate macro for inserting fields in struct in the standard lib

**URL:** <https://discourse.julialang.org/t/separate-macro-for-inserting-fields-in-struct-in-the-standard-lib/59090>\
**Category:** General Usage\
**Tags:** macros\
**Created:** [April 12, 2021, 10:43am UTC](https://discourse.julialang.org/t/separate-macro-for-inserting-fields-in-struct-in-the-standard-lib/59090 "2021-04-12T10:43:19Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [April 12, 2021, 8:40pm UTC](https://discourse.julialang.org/t/separate-macro-for-inserting-fields-in-struct-in-the-standard-lib/59090/2 "2021-04-12T20:40:06Z")

</div>

You could use [CompositeStructs.jl](https://discourse.julialang.org/t/ann-compositestructs-jl/58902):

```julia
using CompositeStructs

struct MyFields
    weights
    input_dim
    output_dim
end

@composite mutable struct MyStruct
    MyFields...
end

```

In this case `MyFields` is also a struct, if you want to make sure no one can make an instance of `MyFields` and it serves only as a list of fields, you could also add an inner constructor `MyFields() = error()`.

---

_[View the full topic](https://discourse.julialang.org/t/separate-macro-for-inserting-fields-in-struct-in-the-standard-lib/59090)._
