5 ms·
Still learning rust. What's the unwrap() for in the last line of the consumer code: stdout().write(output).unwrap(); Thanks.
by wpollock 2y ago
Still learning rust. What's the unwrap() for in the last line of the consumer code:
stdout().write(output).unwrap();
Thanks.
- ynik 2y agoIt causes a panic if the write to stdout fails (e.g. if it's a pipe and the other side was closed, or if stdout is redirected to a file and the disk is full). The rust compiler requires handling this potential error in some way, or you get a compiler error. unwrap() "handles" the IO error by crashing the program with a panic, which is the simplest way of avoiding the compiler error. It's fine for such a toy program, but would be inappropriate for production code.
- deleted 2y ago[deleted]