How to Read A File Concurrently

In Golang I can use this but for Rust I can only think reading file to a Vec and using rayon for iterating on list in parallel is there any more efficient way?

As far as I can tell, this is equivalent to your go code.

use crossbeam::channel::{bounded, Receiver};
use std::fs::File;
use std::io::{BufRead, BufReader};

const CONCURRENCY: usize = 100;

fn main() -> std::io::Result<()> {
    let (send, recv) = bounded(1024);
    let mut join_handles = Vec::with_capacity(CONCURRENCY);
    for _ in 0..CONCURRENCY {
        let recv = recv.clone();
        let handle = std::thread::spawn(move || start_working(recv));
    let file = File::open("/path/to/csv")?;
    for line in BufReader::new(file).lines() {
    for handle in join_handles {

fn start_working(recv: Receiver<String>) {
    while let Ok(line) = recv.recv() {
        println!("Got line: {}", line);


1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.