Streaming Rust

Rust さんぽ

shard rocks db

Other tips


std::mpsc::Sender is !Sync (which means you need to wrap it with a Mutex or similar) where crossbeam::channel::Sender is Sync. Other than the perforance gains, seems like crossbeam is status quo.

accessing the tokio’s runtime from other threads

we don’t want multiple runtimes in one app.

use std::thread;

async fn main() {
    thread::spawn(move ||{

async fn async_function() {

but there might be situations that we want to fun async functions inside our dedicated thread.

in that case you get the handle of the runtime and use that

use tokio::runtime::Handle;

let handle = Handle::current();

handle.spawn(async move{

other small things

const or static

Almost always use const. I guess when const it lives in the binary, on the otherhand when it’s a static it has a memory assigned and could be modified through unsafe operations.

Date: 2023-08-03 Thu 14:08