ByteCursor structv0.1.0
pub struct ByteCursor {
// private fields
}
Constructors
ByteCursor
pub func ByteCursor(room: var char8[..]) -> ByteCursor
A cursor over room, filling from its start.
| Name | Type | Description |
|---|---|---|
room | var char8[..] | how many bytes the buffer holds |
Returns: a cursor over that storage, having written nothing
Methods
Push
pub func Push(self: &var ByteCursor, byte: char8)
Appends one byte, or records an overrun when there is no room.
| Name | Type | Description |
|---|---|---|
byte | char8 | the byte |
PushBytes
pub func PushBytes(self: &var ByteCursor, bytes: char8[..])
Appends every byte of bytes, or records an overrun when they do not all fit.
| Name | Type | Description |
|---|---|---|
bytes | char8[..] | the bytes |
Written
pub func Written(self: &ByteCursor) -> char8[..]
What has been written.
Returns: the bytes written so far, borrowed
Overran
pub func Overran(self: &ByteCursor) -> bool
Whether a write was refused for want of room.
Returns: whether more was pushed than the buffer holds, which silently dropped the excess
Implements TextWriter
ByteCursor conforms to TextWriter.
Write
pub func Write(
self: &var ByteCursor,
bytes: char8[..]
) -> ! FormatError
Writes bytes into the buffer.
Reports InsufficientCapacity when the bytes do not all fit. The cursor is a bounded destination, so this
is the failure it exists to report; a WriterFailure is impossible, since there is no destination beyond
the buffer, and the bytes are not revalidated here, so no TextFailure arises either.
Unlike a builder, a cursor that overruns keeps whatever fitted rather than leaving itself unchanged: the
buffer is the caller's, the partial content is visible through Written, and Overran says it is partial.
| Name | Type | Description |
|---|---|---|
bytes | char8[..] | the UTF-8 run to write |
Returns: success when every byte fitted