File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed
examples/std_misc/process/pipe Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -16,21 +16,23 @@ fn main() {
1616 } ;
1717
1818 {
19- // Write a string to the stdin of `wc`
19+ // Write a string to the `stdin` of `wc`.
20+ //
21+ // `stdin` has type `Option<ChildStdin>`, but since we know this instance
22+ // must have one, we can directly `unwrap` it.
2023 match process. stdin . unwrap ( ) . write_all ( PANGRAM . as_bytes ( ) ) {
2124 Err ( why) => panic ! ( "couldn't write to wc stdin: {}" ,
2225 Error :: description( & why) ) ,
2326 Ok ( _) => println ! ( "sent pangram to wc" ) ,
2427 }
2528
26- // `stdin` gets `drop`ed here, and the pipe is closed
29+ // `stdin` gets `drop`ed here, and the pipe is closed.
30+ //
2731 // This is very important, otherwise `wc` wouldn't start processing the
28- // input we just sent
32+ // input we just sent.
2933 }
3034
31- // The `stdout` field also has type `Option<PipeStream>`
32- // the `as_mut` method will return a mutable reference to the value
33- // wrapped in a `Some` variant
35+ // The `stdout` field also has type `Option<ChildStdout>` so must be unwrapped.
3436 let mut s = String :: new ( ) ;
3537 match process. stdout . unwrap ( ) . read_to_string ( & mut s) {
3638 Err ( why) => panic ! ( "couldn't read wc stdout: {}" ,
You can’t perform that action at this time.
0 commit comments