0

I have two Rust threads; to send a struct from one thread to another I would use a channel. Now I want to split these threads into two OS processes.

Is there a simpler way than using a TCP socket and serializing to JSON back and forth?

I'm fairly new to all of this so I don't even know what terms to Google.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
yawn
  • 422
  • 1
  • 5
  • 21
  • [Relevant question](https://stackoverflow.com/q/27683266/1233251). There is no direct means of IPC in the standard library, but multiple crates are available for this. – E_net4 Dec 18 '17 at 21:22
  • Thanks. I'm a bit overwhelmed by options. What crates do you use personally? – yawn Dec 18 '17 at 22:18

1 Answers1

1

In terms of what to google for the keyword you are looking for is inter-process communication (IPC). There are several ways of doing that and as already mentioned in a comment, Rust doesn't offer much in the standard library.

The thing is that there are many ways to do inter-process communication, each with its own benefits and draw-backs. Maybe start reading here, it will give you some hints on what to google for.

Specifically for your question, if you are concerned about performance when serializing your structs to json you can stick to binary formats as well. Bson might be an option you can have a look at.

StarSheriff
  • 1,477
  • 2
  • 17
  • 23
  • Thank you. I'm reading into different options right now. I'm mostly looking for something that's really easy rather than something efficient. Ideally it would "just work" like channels. – yawn Dec 18 '17 at 22:20
  • 1
    I am afraid that there is no real "easy" way of doing IPC, you will have some or another overhead. I would say TCP/Unix sockets are among the easier ways. Anyway, you have to serialize your data somehow. To get rid of the json complexity you could serialize to plain `[u8]`, that is raw bytes. Take a look at [this SO question](https://stackoverflow.com/questions/28127165/how-to-convert-struct-to-u8) – StarSheriff Dec 19 '17 at 07:09