I'm just starting out in Rust and I find the concept of ownership confusing so I wrote an implementation of the echo
command. I would like to know if I could have set the initial value on the echo
variable any better or just any general improvements.
use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
let mut echo: String;
if let Some(string) = args.get(1) {
echo = string.to_string();
} else {
return;
}
for arg in &args[2..] {
echo.push(' ');
echo.push_str(arg.as_str());
}
echo.push('\n');
println!("{}", echo);
}