# How to apply two macros to a struct definition?

**URL:** <https://discourse.julialang.org/t/how-to-apply-two-macros-to-a-struct-definition/37957>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [April 21, 2020, 11:22am UTC](https://discourse.julialang.org/t/how-to-apply-two-macros-to-a-struct-definition/37957 "2020-04-21T11:22:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [April 21, 2020, 11:22am UTC](https://discourse.julialang.org/t/how-to-apply-two-macros-to-a-struct-definition/37957/1 "2020-04-21T11:22:28Z")

</div>

I would like to use two macros to add extra functions to one struct, namely  
@with\_kw (from [Parameters.jl](https://github.com/mauro3/Parameters.jl) )  
and  
@auto\_hash\_equals (from [AutoHashEquals.jl](https://github.com/andrewcooke/AutoHashEquals.jl) ).

```julia
using Parameters, AutoHashEqual
@with_kw @auto_hash_equals struct S1
    x::Float64 = 1.0
end
@auto_hash_equals @with_kw struct S2 
    x::Float64 = 1.0
end

```

Is there a way to apply both macros at the same time? Thanks!

I get the following errors.

For `S1`:

```julia
ERROR: LoadError: Only works on type-defs or named tuples.
Make sure to have a space after `@with_kw`, e.g. `@with_kw (a=1,)
Also, make sure to use a trailing comma for single-field NamedTuples.

Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] with_kw(::Expr, ::Module, ::Bool) at /home/plunder/.juliapro/JuliaPro_v1.0.5-2/packages/Parameters/l76EM/src/Parameters.jl:307
 [3] @with_kw(::LineNumberNode, ::Module, ::Any) at /home/plunder/.juliapro/JuliaPro_v1.0.5-2/packages/Parameters/l76EM/src/Parameters.jl:631
in expression starting at REPL[11]:1

```

For `S2`:

```julia
ERROR: LoadError: AssertionError: typ.head == :type || typ.head == :struct
Stacktrace:
 [1] @auto_hash_equals(::LineNumberNode, ::Module, ::Any) at /home/plunder/.juliapro/JuliaPro_v1.0.5-2/packages/AutoHashEquals/tDuUH/src/AutoHashEquals.jl:67
in expression starting at REPL[9]:1

```

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [April 21, 2020, 12:54pm UTC](https://discourse.julialang.org/t/how-to-apply-two-macros-to-a-struct-definition/37957/2 "2020-04-21T12:54:22Z")

</div>

I don’t think there is an easy way. Both macros produce more than just a type-def, but both expect a type-def as an input. The only way to do this would be to make them somehow compatible.

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [April 29, 2020, 6:50pm UTC](https://discourse.julialang.org/t/how-to-apply-two-macros-to-a-struct-definition/37957/3 "2020-04-29T18:50:46Z")

</div>

Thanks for the reply! Guess it is just not possible.
