# So if I have module A defining a struct, then with "using" import the struct to mo

**URL:** <https://discourse.julialang.org/t/so-if-i-have-module-a-defining-a-struct-then-with-using-import-the-struct-to-mo/54704>\
**Category:** General Usage\
**Tags:** package, development, module\
**Created:** [February 5, 2021, 9:07pm UTC](https://discourse.julialang.org/t/so-if-i-have-module-a-defining-a-struct-then-with-using-import-the-struct-to-mo/54704 "2021-02-05T21:07:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Post date:** [February 5, 2021, 9:07pm UTC](https://discourse.julialang.org/t/so-if-i-have-module-a-defining-a-struct-then-with-using-import-the-struct-to-mo/54704/1 "2021-02-05T21:07:30Z")

</div>

So if I have module A defining a struct, then with “using” import the struct to module B, and define a function on that struct. Then in module C “using” import both module A and B. When I try to run the function on the struct I get a method error. Is there any way to make the struct imported from A and methods from B apply to each other appropriately? MWE:  
exampleimport.jl  
`module ExampleImport`  
`mutable struct TestStruct`  
`val::Int`  
`end`  
`export TestStruct`  
`end`

exampleimport2.jl  
`module ExampleImport2`  
`include("exampleimport.jl")`  
`using .ExampleImport`  
`function teststructmod!(x::TestStruct)`  
`x.val = 10`  
`end`  
`export teststructmod!`  
`end`

example.jl  
`include("exampleimport.jl")`  
`include("exampleimport2.jl")`

`using .ExampleImport2`  
`using .ExampleImport`

`tmp = TestStruct(2)`

`teststructmod!(tmp)`

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1612559129131100?thread_ts=1612559129.131100&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

**Author:** ![macd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/macd/32/3257_2.png) [@macd](https://discourse.julialang.org/u/macd)\
**Post date:** [February 5, 2021, 10:14pm UTC](https://discourse.julialang.org/t/so-if-i-have-module-a-defining-a-struct-then-with-using-import-the-struct-to-mo/54704/2 "2021-02-05T22:14:05Z")

</div>

You can make this exact example work by using Reexport.jl. Keep module 1 the same. In 2 use

```julia
using Reexport
@reexport using .ExampleImport

```

and then remove `include("exampleimport.jl")` and `using .ExampleImport` from `example.jl`

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [February 6, 2021, 4:41am UTC](https://discourse.julialang.org/t/so-if-i-have-module-a-defining-a-struct-then-with-using-import-the-struct-to-mo/54704/3 "2021-02-06T04:41:25Z")

</div>

You may find interesting this tutorial on modules and packages:

> **[11 - Developing Julia packages](https://syl1.gitbook.io/julia-language-a-concise-tutorial/language-core/11-developing-julia-packages)**
