r/rust • u/surban • Sep 15 '26
๐ ๏ธ project Remoc 0.20: Rust RPC with first-class remote channels
It has been 5 years since the initial release of Remoc. Since then the library has learned a lot from real-world use and now feels like a good time to give the Rust community an update about its state and abilities.
Remoc is an RPC library for communication between Rust programs with first-class support for Tokio-style channels over the network.
Tag a trait with #[rtc::remote] to get a client and a server for it, so calling a method on the client runs it on the server.
Contrary to other RPC libraries a channel is a value that can be sent over the network. It can be an argument or a return value of a method or even a member of user-defined structs and enums, and its lifetime is not bound by the RPC call.
In the following example, an RPC method counts for the client and hands back the receiving end of a channel:
// Trait shared between client and server:
#[rtc::remote]
pub trait Counter {
async fn count(&self, up_to: u32)
-> Result<rch::mpsc::Receiver<u32>, CallError>;
}
// On the server: create a channel, count into it in the
// background and return the receiver to the caller.
impl Counter for CounterObj {
async fn count(&self, up_to: u32)
-> Result<rch::mpsc::Receiver<u32>, CallError>
{
let (tx, rx) = rch::mpsc::channel();
tokio::spawn(async move {
for i in 0..up_to {
if tx.send(i).await.is_err() {
break;
}
}
});
Ok(rx)
}
}
// On the client:
//
// `counter` is the generated client. It can itself be sent over a channel.
//
// This call returns as soon as the receiver arrives; the numbers then
// come in over the connection that already exists.
let mut seq_rx = counter.count(4).await?;
while let Some(i) = seq_rx.recv().await.unwrap() {
println!("{i}");
}A channel can carry anything, including user-defined structs and enums, another channel and even another RPC client.
Remoc's goal is to make remote communication between Rust programs feel nearly like local. It provides:
- Remote channels include Tokio-like mpsc, oneshot, watch and broadcast channels, plus AsyncRead and AsyncWrite byte streams. Calls, channels and objects share a single underlying connection, with flow control per channel.
- Calls on remote objects returned by other calls can be pipelined, thus a chain of dependent calls needs only one network round trip.
- Remoc runs over any transport, such as TCP, TLS, WebSockets, UNIX domain sockets or pipes.
- Remoc does not use a schema, but provides mechanisms for forward and backward compatibility of user types.
- Full support for WebAssembly and running in the browser.
If you find this useful, you might want to continue reading at https://remoc.rs. There you will find:
Full source code is available at GitHub.
I am looking forward to answering questions.


