Module remoc::rch::base

source ·
Available on crate feature rch only.
Expand description

A channel that exchanges values of arbitrary type with a remote endpoint and is primarily used as the initial channel after establishing a connection with a remote endpoint.

Each value is serialized into binary format before sending and deserialized after it has been received.

The sender and receiver of this channel cannot be sent to a remote endpoint. However, you can send (objects containing) senders and receivers of other channel types (for example mpsc, oneshot or watch) via this channel to a remote endpoint.

§Example

In the following example the client sends a number over a base channel to the server. The server converts it into a string and sends it back over another base channel. The base channels have been obtained using a connect function.

use remoc::prelude::*;

// This would be run on the client.
async fn client(mut tx: rch::base::Sender<u16>, mut rx: rch::base::Receiver<String>) {
    tx.send(1).await.unwrap();
    assert_eq!(rx.recv().await.unwrap(), Some("1".to_string()));

    tx.send(2).await.unwrap();
    assert_eq!(rx.recv().await.unwrap(), Some("2".to_string()));

    tx.send(3).await.unwrap();
    assert_eq!(rx.recv().await.unwrap(), Some("3".to_string()));
}

// This would be run on the server.
async fn server(mut tx: rch::base::Sender<String>, mut rx: rch::base::Receiver<u16>) {
    while let Some(number) = rx.recv().await.unwrap() {
        tx.send(number.to_string()).await.unwrap();
    }
}

Structs§

  • This future resolves when the remote endpoint has closed its receiver.
  • Gathers ports sent from the remote endpoint during deserialization.
  • Gathers ports to send to the remote endpoint during object serialization.
  • Receives arbitrary values from a remote endpoint.
  • An error that occurred during remote sending.
  • Sends arbitrary values to a remote endpoint.

Enums§

  • Creating the remote channel failed.
  • An error that occurred during receiving from a remote endpoint.
  • Error kind that occurred during remote sending.

Traits§

  • Extensions for base channels.

Functions§

  • Create a remote channel over an existing chmux connection.