StreamWriter structv0.1.0

Source
A TextWriter over any stream, recording the stream's failure where the caller can see it.
pub struct StreamWriter {
    // private fields
}

The same two halves as ConsoleWriter, over a destination the caller chose: a file, a buffered writer, a pipe. It is what lets a value describe itself into a stream at all — Display writes into a TextWriter and a stream takes bytes, and until something stands between them a value can only be rendered to standard output or into memory. Whole runs go out through WriteAll, so a stream that takes a partial write is looped over rather than losing the rest of a value's text. The slot must outlive the writer. It is a stored address, so nothing here tracks that.

Constructors

StreamWriter

pub func StreamWriter(
    sink: Writer,
    failure: *var IoError?
) -> StreamWriter

A text writer over sink, recording into failure. sink is borrowed for the call and kept. 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.

NameTypeDescription
sinkWriterwhere the bytes go
failure*var IoError?where the first stream failure is recorded, none until there is one

Returns: a text writer over that stream

Source

Implements TextWriter

StreamWriter conforms to TextWriter.

Write

pub func Write(
    self: &var StreamWriter,
    bytes: char8[..]
) -> ! FormatError

Writes bytes to the stream. 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 part-way through rendering does not go on writing into a destination that has already failed.

NameTypeDescription
byteschar8[..]the UTF-8 run to write

Returns: success when the stream accepted the whole run

Source