Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Change the code to handle an error without a change method signature?
I have a code:
let mut res = vec![];
for mut pipe_cmd in piped {
pipe_cmd = pipe_cmd.into_iter().map(|el| interpolate_env(el)).collect();
pipe_cmd = expand_wildcard(&cwd, pipe_cmd);
pipe_cmd = expand_alias(&aliases, pipe_cmd);
res = call_process_piped(pipe_cmd.clone(), &cwd, &res, &child_env).unwrap();
}
It's compiled and runs great until call_process_piped
returns error. I tried to modify the code like:
let mut res = vec![];
for mut pipe_cmd in piped {
pipe_cmd = pipe_cmd.into_iter().map(|el| interpolate_env(el)).collect();
pipe_cmd = expand_wildcard(&cwd, pipe_cmd);
pipe_cmd = expand_alias(&aliases, pipe_cmd);
match call_process_piped(pipe_cmd.clone(), &cwd, res, &child_env) {
Ok(next_res) => { res = next_res; }
Err(err) => {eprintln!("error {err} in call {pipe_cmd:?}");break}
}
}
But it stopped to compile complaining that res
is consumed and can't be revived back in the Ok' branch. How can I change the code without changing
call_process_piped` signature?
3 posts - 2 participants
🏷️ Rust_feed