ConsoleWriter structv0.1.0
pub struct ConsoleWriter {
// private fields
}
The protocol has one case for a destination failing, WriterFailure, and deliberately no room for the details:
Text has no vocabulary for a broken pipe and does not pretend to. So this adapter keeps both halves. It reports
WriterFailure to the formatter, which stops the write, and records the original IoError in the slot it was
built over, which is what the caller reads afterwards. Nothing about the stream failure is lost, and nothing
about it leaks into a package that could not interpret it. The slot starts as none, and holds the failure once
there is one.
The slot must outlive the writer. It is a stored address, so nothing here tracks that.
Constructors
ConsoleWriter
pub func ConsoleWriter(failure: *var IoError?) -> ConsoleWriter
A writer over standard output, recording into failure.
The slot is read before every write as well as written on failure, so a writer built over a slot that
already holds a failure writes nothing at all.
| Name | Type | Description |
|---|---|---|
failure | *var IoError? | where the first stream failure is recorded, none until there is one |
Returns: a writer over standard output
Implements TextWriter
ConsoleWriter conforms to TextWriter.
Write
pub func Write(
self: &var ConsoleWriter,
bytes: char8[..]
) -> ! FormatError
Writes bytes to standard output.
Reports WriterFailure when the stream refuses, having recorded the original IoError in the slot. Once a
failure has been recorded every later write is refused without touching the stream, so a value that is
part-way through rendering does not go on writing into a handle that has already failed, and a trailing
newline is not emitted after a failed line. This is the only case this writer can produce: the bytes are not
revalidated, and standard output is not a bounded destination.
| Name | Type | Description |
|---|---|---|
bytes | char8[..] | the UTF-8 run to write |
Returns: success when the stream accepted the whole run