Hey, i started to learn Rust few days ago and would like to get some feedback how to do things rusty. Right now, I want to form an array of args for Command, which depends on a function input. My current code looks like this and works as expected. I have a feeling that it is ugly. How can I improve this code?
fn start_process(&self) -> io::Result<impl Write> {
let format = &format!("{0}/{1}", self.x, self.y);
let background;
let args = {
let input = ["-w", format];
if self.background.is_some() {
background = self.background.as_ref().unwrap();
[
&[&background],
&input[..],
&["/tmp/1.txt"],
].concat()
} else {
[&["-f"], &input[..], &["/tmp/1.txt"]].concat()
}
};
let child = Command::new("some_program")
.args(&args)
.stdin(Stdio::piped())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()?;
let stdin = child
.stdin
.ok_or_else(|| IoError::new(IoErrorKind::Other, "jkljkll"))?;
Ok(stdin)
}