diff --git a/examples/std_misc/process/pipe/pipe.rs b/examples/std_misc/process/pipe/pipe.rs index 41747b255b..98e112e127 100644 --- a/examples/std_misc/process/pipe/pipe.rs +++ b/examples/std_misc/process/pipe/pipe.rs @@ -15,23 +15,22 @@ fn main() { Ok(process) => process, }; - { - // Write a string to the `stdin` of `wc`. - // - // `stdin` has type `Option`, but since we know this instance - // must have one, we can directly `unwrap` it. - match process.stdin.unwrap().write_all(PANGRAM.as_bytes()) { - Err(why) => panic!("couldn't write to wc stdin: {}", - Error::description(&why)), - Ok(_) => println!("sent pangram to wc"), - } - - // `stdin` gets `drop`ed here, and the pipe is closed. - // - // This is very important, otherwise `wc` wouldn't start processing the - // input we just sent. + // Write a string to the `stdin` of `wc`. + // + // `stdin` has type `Option`, but since we know this instance + // must have one, we can directly `unwrap` it. + match process.stdin.unwrap().write_all(PANGRAM.as_bytes()) { + Err(why) => panic!("couldn't write to wc stdin: {}", + Error::description(&why)), + Ok(_) => println!("sent pangram to wc"), } + // Because `stdin` does not live after the above calls, it is `drop`ed, + // and the pipe is closed. + // + // This is very important, otherwise `wc` wouldn't start processing the + // input we just sent. + // The `stdout` field also has type `Option` so must be unwrapped. let mut s = String::new(); match process.stdout.unwrap().read_to_string(&mut s) {