BufferedWriter structv0.1.0
pub struct BufferedWriter {
// private fields
}
Move-only: it owns its buffer. Its destructor flushes as a safety net and discards the outcome, because a
destructor has nowhere to report; the explicit Flush is where errors are seen, and the caller who cares
calls it before letting go.
Associated functions
New
pub func New(
allocator: Allocator,
sink: Writer,
capacity: uint
) -> BufferedWriter ! IoError
A buffered writer over sink with capacity bytes of buffer.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
sink | Writer | where the bytes go |
capacity | uint | how many bytes the buffer holds |
Returns: the buffered stream; Other when the allocator refused the buffer
Methods
Pending
pub func Pending(self: &BufferedWriter) -> uint
How many bytes wait unsent.
Returns: how many bytes are written but not yet flushed
Flush
pub func Flush(self: &var BufferedWriter) -> ! IoError
Sends everything gathered, then asks the sink to flush too.
Returns: success when everything buffered reached the sink
Write
pub func Write(
self: &var BufferedWriter,
bytes: char8[..]
) -> uint ! IoError
Takes bytes: into the buffer while they fit, around it in one piece when they never would.
| Name | Type | Description |
|---|---|---|
bytes | char8[..] | the bytes to write |
Returns: how many bytes were taken, which is all of them
Abandon
pub func Abandon(self: &var BufferedWriter)
Gives the buffer back without sending what it holds. For the caller who has decided the bytes must not go — the one case where losing them is the point.
Destructor
func ~BufferedWriter(self: &var BufferedWriter)
Flushes as a safety net — the outcome has nowhere to go, so a caller who cares flushed already — then gives the buffer back.