Skip to content

Instantly share code, notes, and snippets.

@remram44

remram44/test.rs Secret

Created August 29, 2015 02:21
Show Gist options
  • Save remram44/2e3a755b4107552723c0 to your computer and use it in GitHub Desktop.
Save remram44/2e3a755b4107552723c0 to your computer and use it in GitHub Desktop.
use std::io;
use std::io::Write;
fn main() {
let output = &"hello";
loop {
match write!(&mut io::stdout(), "{}\n", output) {
Ok(_) => {},
Err(e) => {
if e.kind() == io::ErrorKind::BrokenPipe {
write!(&mut io::stderr(), "breaking\n").unwrap();
break
} else {
panic!("My {}", e)
}
},
}
}
write!(&mut io::stderr(), "got out of the loop alive\n").unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment