O'Reilly logo

Rust Essentials by Ivo Balbaert

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Communication through channels

Data can also be exchanged between threads by passing messages among them. This is implemented in Rust by channels, which are like unidirectional pipes that connect two threads—data is processed first-in, first-out. Data flows over this channel between two end-points, from the Sender<T> to the Receiver<T>; both are generic and take the T type of the message to transfer (which obviously must be the same for the Sender and Receiver channels). In this mechanism, a copy of the data to be shared is made for the receiving thread, so you shouldn't use this for very large data:

Communication through channels

To create a channel, we need to import the mpsc ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required