www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - deep copy thread local to shared or how to send() struct with


I need to send Publish struct from 
https://github.com/tchaloupka/vibe-mqtt to another vibe.d task. 
And there is the problem. First of all, I can't make it immutable 
because send() wants to mutate it. I can't send local copy 
because of "Aliases to mutable thread-local data not allowed.". 
And I can't convert it to shared because of "cannot implicitly 
convert expression `packet` of type `Publish` to 

I don't understand error message about FixedHeader. Why it tries 
to convert struct to its field? As I understand the real problem 
here is `ubyte[] payload` dynamic array field in Publish which is 
allocated separately, so to make a shared copy of Publish it need 
the deep copy of this struct. How to do it right? I don't want to 
copy all fields manually, is there a standard way to accomplish 

struct MqttOnPublish
   Publish packet;

   override void onPublish(Publish packet)

      // source/vcm/mqtt/bridge.d(69,41): Error: cannot implicitly 
convert expression `packet` of type `Publish` to 
      shared Publish sp = shared Publish(packet);

/* /usr/include/dmd/phobos/std/concurrency.d(575,5): Error: 
static assert  "Aliases to mutable thread-local data not allowed."
      instantiated from here: send!(MqttOnPublish)
source/vision/eventbus.d(72,27):        instantiated from here: 
source/vision/eventbus.d(42,13):        instantiated from here: 
source/vcm/mqtt/bridge.d(70,14):        instantiated from here: 

Nov 23 2017