5 ms·
The main function is egregiously overcomplicated. This is how I'd write it instead: fn main() { match env::args_os().nth(1) { None =
by agwa 9y ago
The main function is egregiously overcomplicated.
This is how I'd write it instead:
fn main() {
match env::args_os().nth(1) {
None => write(b"y\n"),
Some(arg) => {
let mut arg = to_bytes(arg);
arg.push(b'\n');
write(&arg);
}
}
process::exit(1);
}
It's just as efficient and far more readable. It avoids Cow, a lambda, and the chain of combinators.
- sinistersnare 9y agoDoesn't this only print once, and not over and over, like `yes` should?
- agwa 9y agoThe write function takes care of repeating it. See the complete source code in the blog post.