use std::fs; use std::process::Command; fn do_thrift(n: &str) { let mut cmd = Command::new("thrift"); cmd.arg("-o"); cmd.arg("src"); cmd.arg("--gen"); cmd.arg("rs"); cmd.arg(format!("thrifts/{}.thrift", n)); match cmd.status() { Ok(status) => status, Err(_e) => std::process::exit(1) }; let mut cmd = Command::new("sed"); cmd.arg("-i"); cmd.arg("s/mut TOutputProtocol/mut dyn TOutputProtocol/;s/mut TInputProtocol/mut dyn TInputProtocol/"); cmd.arg(format!("src/{}.rs", n)); match cmd.status() { Ok(status) => status, Err(_e) => std::process::exit(1) }; } fn main() { if let Ok(entries) = fs::read_dir("thrifts") { // Here, `entries` is a `ReadDir`. for entry in entries.filter(|_x| match _x { Ok(_t) => match _t.file_name().to_str() { Some(_s) => _s.ends_with(".thrift"), None => false } Err(_f) => false } ) { let file_name = entry.unwrap().file_name(); let file_str = file_name.to_str().unwrap(); match file_str.get(..file_str.len()-7) { None => (), Some(_s) => do_thrift(_s) } } } }