# Pass struct from module to distributed worker

**URL:** <https://discourse.julialang.org/t/pass-struct-from-module-to-distributed-worker/81905>\
**Category:** General Usage\
**Tags:** module, distributed\
**Created:** [May 30, 2022, 8:14am UTC](https://discourse.julialang.org/t/pass-struct-from-module-to-distributed-worker/81905 "2022-05-30T08:14:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [May 30, 2022, 8:14am UTC](https://discourse.julialang.org/t/pass-struct-from-module-to-distributed-worker/81905/1 "2022-05-30T08:14:38Z")

</div>

For Pluto.jl, I’m trying to pass a struct from a module on the main process to a distributed worker ([Return a `Rich` object instead of `Dict` for `show_richest` by rikhuijzer · Pull Request #2139 · fonsp/Pluto.jl · GitHub](https://github.com/fonsp/Pluto.jl/pull/2139)). Currently, this doesn’t work so `Dict`s and `NamedTuple`s are passed. To fix that, the following is a MWE of what I would like to do:

```julia
using Distributed: Distributed, @everywhere

const Distributed_expr = :(
    Base.loaded_modules[Base.PkgId(Base.UUID("8ba89e20-285c-5b6f-9357-94700520ee1b"), "Distributed")]
)

pid = Distributed.remotecall_eval(Main, 1, quote
    $(Distributed_expr).addprocs(1) |> first
end)

module M
    struct T
        x::Int
    end
    f(x::Int) = T(x)
end

@everywhere pid using .M

t = M.f(1)
@info t

Distributed.remotecall_eval(Main, [pid], quote
    @info M.plus_one($t)
end)

```

This gives various errors currently. Anyone knows how to get something like this to work?

The main problem is that, in Pluto, the distributed workers all load `PlutoRunner` via `include(...)`. This works, but when you pass a struct from the main process to a remote worker, then it will fail with errors such as

```nohighlight
ERROR: MethodError: no method matching f(::Pluto.PlutoRunner.Rich)
Closest candidates are:
  f(::Main.PlutoRunner.Rich) at REPL[1]:1

```
