diff --git a/src/yes/yes.rs b/src/yes/yes.rs index 5e3364c38..8a265fc06 100644 --- a/src/yes/yes.rs +++ b/src/yes/yes.rs @@ -16,6 +16,7 @@ extern crate getopts; extern crate libc; use std::io::print; +use std::borrow::IntoCow; #[path = "../common/util.rs"] #[macro_use] @@ -24,7 +25,7 @@ mod util; static NAME: &'static str = "yes"; pub fn uumain(args: Vec) -> isize { - let program = args[0].clone(); + let program = &args[0]; let opts = [ getopts::optflag("h", "help", "display this help and exit"), getopts::optflag("V", "version", "output version information and exit"), @@ -41,27 +42,24 @@ pub fn uumain(args: Vec) -> isize { println!("Usage:"); println!(" {0} [STRING]... [OPTION]...", program); println!(""); - print(getopts::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", &opts).as_slice()); + print(&getopts::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", &opts)[]); return 0; } if matches.opt_present("version") { println!("yes 1.0.0"); return 0; } - let mut string = "y".to_string(); - if !matches.free.is_empty() { - string = matches.free.connect(" "); - } + let string = if matches.free.is_empty() { + "y".into_cow() + } else { + matches.free.connect(" ").into_cow() + }; - exec(string.as_slice()); + exec(&string[]); 0 } pub fn exec(string: &str) { - loop { - if !pipe_println!("{}", string) { - break; - } - } + while pipe_println!("{}", string) { } }